@@ -45,13 +45,48 @@ const insertCharterSchema = z.object({
4545} ) ;
4646
4747const editCharterSchema = insertCharterSchema . extend ( {
48+ name : z . string ( ) . optional ( ) ,
49+ description : z . string ( ) . optional ( ) ,
50+ groupId : z . string ( ) . optional ( ) ,
51+ isActive : z . boolean ( ) . optional ( ) ,
52+ autoApprove : z . boolean ( ) . optional ( ) ,
53+ allowPosts : z . boolean ( ) . optional ( ) ,
4854 guidelines : z
4955 . array ( z . string ( ) )
5056 . min ( 1 , "At least one guideline is required" ) ,
5157} ) ;
5258
5359type EditCharterForm = z . infer < typeof editCharterSchema > ;
5460
61+ interface Charter {
62+ id : string ;
63+ name : string ;
64+ description ?: string ;
65+ guidelines : string [ ] ;
66+ groupId ?: string ;
67+ isActive : boolean ;
68+ autoApprove : boolean ;
69+ allowPosts : boolean ;
70+ createdAt : Date ;
71+ updatedAt : Date ;
72+ group ?: {
73+ id : string ;
74+ name : string ;
75+ platform : string ;
76+ imageUrl ?: string ;
77+ memberCount ?: number ;
78+ } ;
79+ }
80+
81+ interface Group {
82+ id : string ;
83+ name : string ;
84+ description ?: string ;
85+ platform ?: string ;
86+ imageUrl ?: string ;
87+ memberCount ?: number ;
88+ }
89+
5590export default function EditCharter ( {
5691 params,
5792} : {
@@ -62,15 +97,11 @@ export default function EditCharter({
6297 const [ guidelines , setGuidelines ] = useState < string [ ] > ( [ ] ) ;
6398 const { user } = useAuth ( ) ;
6499
65- const { data : charter , isLoading : charterLoading } = {
66- data : null ,
67- isLoading : false ,
68- } ; // Replace with actual data fetching logic
100+ const charter : Charter | null = null ; // Replace with actual data fetching logic
101+ const charterLoading = false ;
69102
70- const { data : groups , isLoading : groupsLoading } = {
71- data : [ ] ,
72- isLoading : false ,
73- } ; // Replace with actual groups fetching logic
103+ const groups : Group [ ] = [ ] ; // Replace with actual groups fetching logic
104+ const groupsLoading = false ;
74105
75106 const form = useForm < EditCharterForm > ( {
76107 resolver : zodResolver ( editCharterSchema ) ,
@@ -87,33 +118,34 @@ export default function EditCharter({
87118
88119 // Populate form when charter data is loaded
89120 useEffect ( ( ) => {
90- if ( charter && charter . name ) {
91- const guidelines = charter . guidelines || [ ] ;
121+ if ( charter ) {
122+ const charterData = charter as Charter ;
123+ const guidelines = charterData . guidelines || [ ] ;
92124
93- console . log ( "Charter data loaded:" , charter ) ;
94- console . log ( "Charter name:" , charter . name ) ;
95- console . log ( "Charter description:" , charter . description ) ;
125+ console . log ( "Charter data loaded:" , charterData ) ;
126+ console . log ( "Charter name:" , charterData . name ) ;
127+ console . log ( "Charter description:" , charterData . description ) ;
96128 console . log ( "Charter guidelines:" , guidelines ) ;
97- console . log ( "Charter groupId:" , charter . groupId ) ;
129+ console . log ( "Charter groupId:" , charterData . groupId ) ;
98130
99131 // Set guidelines state first
100132 setGuidelines ( guidelines . length > 0 ? guidelines : [ "" ] ) ;
101133
102134 // Reset form with current charter data
103135 const formValues = {
104- name : charter . name || "" ,
105- description : charter . description || "" ,
136+ name : charterData . name || "" ,
137+ description : charterData . description || "" ,
106138 guidelines : guidelines ,
107- groupId : charter . groupId || undefined ,
139+ groupId : charterData . groupId || undefined ,
108140 isActive :
109- charter . isActive !== undefined ? charter . isActive : true ,
141+ charterData . isActive !== undefined ? charterData . isActive : true ,
110142 autoApprove :
111- charter . autoApprove !== undefined
112- ? charter . autoApprove
143+ charterData . autoApprove !== undefined
144+ ? charterData . autoApprove
113145 : false ,
114146 allowPosts :
115- charter . allowPosts !== undefined
116- ? charter . allowPosts
147+ charterData . allowPosts !== undefined
148+ ? charterData . allowPosts
117149 : true ,
118150 } ;
119151
@@ -124,23 +156,23 @@ export default function EditCharter({
124156
125157 // Also manually set values to ensure they stick
126158 setTimeout ( ( ) => {
127- form . setValue ( "name" , charter . name || "" ) ;
128- form . setValue ( "description" , charter . description || "" ) ;
159+ form . setValue ( "name" , charterData . name || "" ) ;
160+ form . setValue ( "description" , charterData . description || "" ) ;
129161 form . setValue ( "guidelines" , guidelines ) ;
130- form . setValue ( "groupId" , charter . groupId || undefined ) ;
162+ form . setValue ( "groupId" , charterData . groupId || undefined ) ;
131163 form . setValue (
132164 "isActive" ,
133- charter . isActive !== undefined ? charter . isActive : true
165+ charterData . isActive !== undefined ? charterData . isActive : true
134166 ) ;
135167 form . setValue (
136168 "autoApprove" ,
137- charter . autoApprove !== undefined
138- ? charter . autoApprove
169+ charterData . autoApprove !== undefined
170+ ? charterData . autoApprove
139171 : false
140172 ) ;
141173 form . setValue (
142174 "allowPosts" ,
143- charter . allowPosts !== undefined ? charter . allowPosts : true
175+ charterData . allowPosts !== undefined ? charterData . allowPosts : true
144176 ) ;
145177 } , 100 ) ;
146178 }
@@ -286,15 +318,15 @@ export default function EditCharter({
286318 className = { cn (
287319 "w-full justify-between rounded-2xl border border-gray-200 bg-white/80 backdrop-blur-xs px-4 py-3 h-auto" ,
288320 ! field . value &&
289- "text-muted-foreground"
321+ "text-muted-foreground"
290322 ) }
291323 >
292324 { field . value
293325 ? groups ?. find (
294- ( group ) =>
295- group . id ===
296- field . value
297- ) ?. name
326+ ( group ) =>
327+ group . id ===
328+ field . value
329+ ) ?. name
298330 : "Select a group..." }
299331 < ChevronsUpDown className = "ml-2 h-4 w-4 shrink-0 opacity-50" />
300332 </ Button >
@@ -345,7 +377,7 @@ export default function EditCharter({
345377 </ span >
346378 < PlatformBadge
347379 platform = {
348- group . platform
380+ group . platform || "unknown"
349381 }
350382 />
351383 </ div >
@@ -412,9 +444,8 @@ export default function EditCharter({
412444 className = "flex items-center space-x-3"
413445 >
414446 < Input
415- placeholder = { `Guideline ${
416- index + 1
417- } `}
447+ placeholder = { `Guideline ${ index + 1
448+ } `}
418449 className = "flex-1 px-4 py-3 rounded-2xl border border-gray-200 focus:border-amber-500 focus:ring-2 focus:ring-amber-200 transition-all duration-200 bg-white/80 backdrop-blur-xs"
419450 value = { guideline }
420451 onChange = { ( e ) =>
0 commit comments