Skip to content

Commit

Permalink
refactor: types and mutation function name
Browse files Browse the repository at this point in the history
  • Loading branch information
Farhan-slurrp committed Aug 27, 2023
1 parent dbd632d commit 5b54e20
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions packages/api/src/hooks/useSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import useInvalidateQuery from '../useInvalidateQuery';
import useRequest from '../useRequest';

type TSetSettingsPayload = NonNullable<
NonNullable<Parameters<ReturnType<typeof useRequest<'set_settings'>>['mutate']>>[0]
>['payload'];
NonNullable<NonNullable<Parameters<ReturnType<typeof useRequest<'set_settings'>>['mutate']>>[0]>['payload']
>;

/** A custom hook to get user settings (email, date of birth, address etc) */
const useSettings = () => {
Expand All @@ -15,18 +15,15 @@ const useSettings = () => {
onSuccess: () => invalidate('get_settings'),
});

const setSettings = useCallback(
(values: NonNullable<TSetSettingsPayload>) => mutate({ payload: { ...values } }),
[mutate]
);
const update = useCallback((values: TSetSettingsPayload) => mutate({ payload: { ...values } }), [mutate]);

const modified_data = useMemo(() => ({ ...data?.get_settings }), [data?.get_settings]);

return {
/** User information and settings */
data: modified_data,
/** Function to update user settings */
setSettings,
update,
mutation: mutate_rest,
...rest,
};
Expand Down

0 comments on commit 5b54e20

Please sign in to comment.