@@ -61,7 +61,6 @@ const fields: Field[] = [
61
61
{ name : "users" , label : "Users (one email per line)" , type : "textarea" } ,
62
62
] ;
63
63
64
-
65
64
export default function GroupsPage ( ) {
66
65
const params = useParams ( ) ;
67
66
const orgId = params . orgId as string ;
@@ -135,54 +134,53 @@ export default function GroupsPage() {
135
134
try {
136
135
// Create a copy of the group object to avoid mutating the original
137
136
const groupToSave = { ...group } ;
138
-
137
+
139
138
// Convert users from string to array of strings (splitting at newlines)
140
- if ( typeof groupToSave . users === ' string' ) {
139
+ if ( typeof groupToSave . users === " string" ) {
141
140
groupToSave . users = groupToSave . users
142
- . split ( '\n' )
143
- . map ( user => user . trim ( ) )
144
- . filter ( user => user . length > 0 ) ; // Remove empty lines
141
+ . split ( "\n" )
142
+ . map ( ( user ) => user . trim ( ) )
143
+ . filter ( ( user ) => user . length > 0 ) ; // Remove empty lines
145
144
}
146
-
145
+
147
146
console . log ( "groups" , groupToSave ) ;
148
-
147
+
149
148
const url = selectedGroup
150
149
? `/api/orgs/${ orgId } /groups/${ group . nameId } `
151
150
: `/api/orgs/${ orgId } /groups` ;
152
-
151
+
153
152
const response = await fetch ( url , {
154
153
method : selectedGroup ? "PATCH" : "POST" ,
155
154
headers : {
156
155
"Content-Type" : "application/json" ,
157
156
} ,
158
157
body : JSON . stringify ( groupToSave ) ,
159
158
} ) ;
160
-
159
+
161
160
if ( ! response . ok ) {
162
161
const errorData = await response . json ( ) . catch ( ( ) => ( { } ) ) ;
163
162
throw new Error ( formatValidationErrors ( errorData ) ) ;
164
163
}
165
-
164
+
166
165
const savedGroup = await response . json ( ) ;
167
166
// console.log('saved groups',savedGroup);
168
-
169
-
167
+
170
168
if ( selectedGroup ) {
171
169
setGroups ( groups . map ( ( g ) => ( g . id === savedGroup . id ? savedGroup : g ) ) ) ;
172
170
toast ( {
173
171
title : "Success" ,
174
172
description : "Group updated successfully" ,
175
173
} ) ;
176
174
} else {
177
- console . log ( "savedgroups" , savedGroup ) ;
178
-
175
+ console . log ( "savedgroups" , savedGroup ) ;
176
+
179
177
setGroups ( [ ...groups , savedGroup ] ) ;
180
178
toast ( {
181
179
title : "Success" ,
182
180
description : "Group created successfully" ,
183
181
} ) ;
184
182
}
185
-
183
+
186
184
setIsEditorOpen ( false ) ;
187
185
} catch ( error ) {
188
186
console . error ( "Error saving group:" , error ) ;
0 commit comments