-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/817 copy another user rights for a new user #899
Changes from 1 commit
ff2d5c9
04bc18b
1a1383c
aa2a21b
932fca5
a2ea411
ab9579e
b1e9f73
89fed1b
2ac4aac
382c2fe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,24 +83,12 @@ export function Users() { | |
}, | ||
} | ||
); | ||
const inviteUserMutation = useMutation< | ||
{ invitationUrl?: string } | null, | ||
Error, | ||
{ admin: boolean; email: string; rights: TRights; userToCopy: string } | ||
>((data) => { | ||
if (data.userToCopy) { | ||
return queryUser(data.userToCopy) | ||
.then((res) => { | ||
data.rights = res.rights; | ||
return createInvitation(data.email, data.admin, data.rights); | ||
}) | ||
.catch((error) => { | ||
throw new Error(error); | ||
}); | ||
} else { | ||
return createInvitation(data.email, data.admin, data.rights); | ||
} | ||
}); | ||
const inviteUserMutation = useMutation( | ||
(data: { email: string; admin: boolean; rights: TRights }) => | ||
createInvitation(data.email, data.admin, data.rights) | ||
); | ||
|
||
const readUser = useMutation((user: string) => queryUser(user)); | ||
|
||
function OperationToggleForm(props: { | ||
bulkOperation: string; | ||
|
@@ -319,7 +307,7 @@ export function Users() { | |
type: "bool", | ||
}, | ||
rights: { | ||
label: "", | ||
label: () => "", | ||
type: "object", | ||
array: true, | ||
visible: ({ rawValues }) => !rawValues.useCopyUserRights, | ||
|
@@ -351,14 +339,34 @@ export function Users() { | |
), | ||
}, | ||
}} | ||
onSubmit={async (ctx) => { | ||
onSubmit={(ctx) => { | ||
const backendRights = rightStateArrayToBackendMap(ctx.rights); | ||
const payload = { | ||
let payload = { | ||
rights: backendRights, | ||
admin: ctx.admin, | ||
email: ctx.email, | ||
userToCopy: ctx.userToCopy?.value, | ||
}; | ||
if (ctx.userToCopy) { | ||
readUser | ||
.mutateAsync(ctx.userToCopy.value) | ||
.then((res: TUser) => { | ||
payload = { ...payload, rights: res.rights }; | ||
return inviteUserMutation | ||
.mutateAsync(payload) | ||
.then((response) => { | ||
if (response && response.invitationUrl) { | ||
setCreationUrl(response.invitationUrl); | ||
} | ||
setCreating(false); | ||
}) | ||
.catch((error) => { | ||
throw new Error(error); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As I told you in my previous review, this kind of code is not very usefull, since you just rethrow the error. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think about this version :
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Its better, except that your code is using async/await (see my previous comment about that) and that it remains a catch that just rethrow the error (as I mentionned twice already, I don't see the point). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ptitFicus , I commit a modification without Async and double throwing error. |
||
}); | ||
}) | ||
.catch((error: any) => { | ||
throw new Error(error); | ||
}); | ||
} | ||
return inviteUserMutation | ||
.mutateAsync(payload) | ||
.then((response) => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since queryUser doesn't change anything server side it should be a query. However I would prefer not having a query at all, and chaining it with
createInvitation
as it was done before (sorry, I told you that userToCopy wasn't necessary anymore, however you'll need it to know it you need to queryUser or not).Having this logic in mutation makes more sense to me, rather than bloating jsx with this logic.