Skip to content

Commit 80728c7

Browse files
committed
update mutation to show proper errors
1 parent 5e0a6cd commit 80728c7

File tree

1 file changed

+26
-15
lines changed
  • app/[locale]/dashboard/[entityType]/[entitySlug]/admin

1 file changed

+26
-15
lines changed

app/[locale]/dashboard/[entityType]/[entitySlug]/admin/addUser.tsx

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,14 @@ import { FetchUsers } from '../usecases/edit/[id]/contributors/query';
1717
const addUserDoc: any = graphql(`
1818
mutation addUserToOrganization($input: AddRemoveUserToOrganizationInput!) {
1919
addUserToOrganization(input: $input) {
20-
__typename
21-
... on TypeOrganizationMembership {
20+
success
21+
errors {
22+
nonFieldErrors
23+
fieldErrors {
24+
messages
25+
}
26+
}
27+
data {
2228
role {
2329
name
2430
id
@@ -118,18 +124,24 @@ const AddUser = ({
118124
input
119125
),
120126
{
121-
onSuccess: (res: any) => {
122-
toast('User added successfully');
123-
// Optionally, reset form or perform other actions
124-
setIsOpen(false);
125-
setFormData({
126-
userId: '',
127-
roleId: '',
128-
});
129-
setRefetch(true);
130-
},
131-
onError: (err: any) => {
132-
toast('Failed to add user');
127+
onSuccess: (data: any) => {
128+
if (data.addUserToOrganization.success) {
129+
toast('User added successfully');
130+
setIsOpen(false);
131+
setFormData({
132+
userId: '',
133+
roleId: '',
134+
});
135+
setRefetch(true);
136+
} else {
137+
toast(
138+
'Error: ' +
139+
(data.addUserToOrganization?.errors?.fieldErrors
140+
? data.addUserToOrganization?.errors?.fieldErrors[0]
141+
?.messages[0]
142+
: data.addUserToOrganization?.errors?.nonFieldErrors[0])
143+
);
144+
}
133145
},
134146
}
135147
);
@@ -146,7 +158,6 @@ const AddUser = ({
146158
{
147159
onSuccess: (res: any) => {
148160
toast('User updated successfully');
149-
// Optionally, reset form or perform other actions
150161
setIsOpen(false);
151162
setFormData({
152163
userId: '',

0 commit comments

Comments
 (0)