Skip to content

Commit 21a3817

Browse files
committed
fix hooks in EditUser
1 parent fde7ec6 commit 21a3817

File tree

1 file changed

+33
-29
lines changed

1 file changed

+33
-29
lines changed

Diff for: packages/desktop-client/src/components/modals/EditUser.tsx

+33-29
Original file line numberDiff line numberDiff line change
@@ -73,50 +73,54 @@ function useGetUserDirectoryErrors() {
7373
return { getUserDirectoryErrors };
7474
}
7575

76-
async function saveUser(
77-
method: 'user-add' | 'user-update',
78-
user: User,
79-
setError: (error: string) => void,
80-
actions: BoundActions,
81-
): Promise<boolean> {
76+
function useSaveUser() {
8277
const { t } = useTranslation();
83-
8478
const { getUserDirectoryErrors } = useGetUserDirectoryErrors();
8579

86-
const { error, id: newId } = (await send(method, user)) || {};
87-
if (!error) {
88-
if (newId) {
89-
user.id = newId;
90-
}
91-
} else {
92-
setError(getUserDirectoryErrors(error));
93-
if (error === 'token-expired') {
94-
actions.addNotification({
95-
type: 'error',
96-
id: 'login-expired',
97-
title: t('Login expired'),
98-
sticky: true,
99-
message: getUserDirectoryErrors(error),
100-
button: {
101-
title: t('Go to login'),
102-
action: () => {
103-
actions.signOut();
80+
async function saveUser(
81+
method: 'user-add' | 'user-update',
82+
user: User,
83+
setError: (error: string) => void,
84+
actions: BoundActions,
85+
): Promise<boolean> {
86+
const { error, id: newId } = (await send(method, user)) || {};
87+
if (!error) {
88+
if (newId) {
89+
user.id = newId;
90+
}
91+
} else {
92+
setError(getUserDirectoryErrors(error));
93+
if (error === 'token-expired') {
94+
actions.addNotification({
95+
type: 'error',
96+
id: 'login-expired',
97+
title: t('Login expired'),
98+
sticky: true,
99+
message: getUserDirectoryErrors(error),
100+
button: {
101+
title: t('Go to login'),
102+
action: () => {
103+
actions.signOut();
104+
},
104105
},
105-
},
106-
});
106+
});
107+
}
108+
109+
return false;
107110
}
108111

109-
return false;
112+
return true;
110113
}
111114

112-
return true;
115+
return { saveUser };
113116
}
114117

115118
export function EditUserFinanceApp({
116119
defaultUser,
117120
onSave: originalOnSave,
118121
}: EditUserFinanceAppProps) {
119122
const { t } = useTranslation();
123+
const { saveUser } = useSaveUser();
120124

121125
return (
122126
<Modal name="edit-user">

0 commit comments

Comments
 (0)