@accounter/client 0.0.8-alpha-20251022132444-51d3ebadb2849ea323e03b88c735cdca4f91db7d → 0.0.8-alpha-20251022144027-c9c7a4b309de8a72dfd0ec4f11e63713ad12878f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/dist/assets/{index-BexxGuN6.js → index-CZb2m31K.js} +297 -292
- package/dist/assets/{index.es-CWwhWGxX.js → index.es-9gVMpHTc.js} +1 -1
- package/dist/index.html +1 -1
- package/package.json +1 -1
- package/src/components/business/admin-business-section.tsx +284 -0
- package/src/components/business/index.tsx +22 -0
- package/src/gql/gql.ts +15 -3
- package/src/gql/graphql.ts +71 -5
- package/src/hooks/use-update-admin-business.ts +71 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import { toast } from 'sonner';
|
|
3
|
+
import { useMutation } from 'urql';
|
|
4
|
+
import {
|
|
5
|
+
UpdateAdminBusinessDocument,
|
|
6
|
+
type UpdateAdminBusinessMutation,
|
|
7
|
+
type UpdateAdminBusinessMutationVariables,
|
|
8
|
+
} from '../gql/graphql.js';
|
|
9
|
+
import { handleCommonErrors } from '../helpers/error-handling.js';
|
|
10
|
+
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions -- used by codegen
|
|
12
|
+
/* GraphQL */ `
|
|
13
|
+
mutation UpdateAdminBusiness($adminBusinessId: UUID!, $fields: UpdateAdminBusinessInput!) {
|
|
14
|
+
updateAdminBusiness(businessId: $adminBusinessId, fields: $fields) {
|
|
15
|
+
id
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
`;
|
|
19
|
+
|
|
20
|
+
type AdminBusiness = UpdateAdminBusinessMutation['updateAdminBusiness'];
|
|
21
|
+
|
|
22
|
+
type UseUpdateBusiness = {
|
|
23
|
+
fetching: boolean;
|
|
24
|
+
updateAdminBusiness: (
|
|
25
|
+
variables: UpdateAdminBusinessMutationVariables,
|
|
26
|
+
) => Promise<AdminBusiness | void>;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const NOTIFICATION_ID = 'updateAdminBusiness';
|
|
30
|
+
|
|
31
|
+
export const useUpdateAdminBusiness = (): UseUpdateBusiness => {
|
|
32
|
+
// TODO: add authentication
|
|
33
|
+
// TODO: add local data update method after change
|
|
34
|
+
|
|
35
|
+
const [{ fetching }, mutate] = useMutation(UpdateAdminBusinessDocument);
|
|
36
|
+
const updateAdminBusiness = useCallback(
|
|
37
|
+
async (variables: UpdateAdminBusinessMutationVariables) => {
|
|
38
|
+
const message = `Error updating admin business ID [${variables.adminBusinessId}]`;
|
|
39
|
+
const notificationId = `${NOTIFICATION_ID}-${variables.adminBusinessId}`;
|
|
40
|
+
toast.loading('Updating admin business', {
|
|
41
|
+
id: notificationId,
|
|
42
|
+
});
|
|
43
|
+
try {
|
|
44
|
+
const res = await mutate(variables);
|
|
45
|
+
const data = handleCommonErrors(res, message, notificationId, 'updateAdminBusiness');
|
|
46
|
+
if (data) {
|
|
47
|
+
toast.success('Success', {
|
|
48
|
+
id: notificationId,
|
|
49
|
+
description: 'Admin Business Updated',
|
|
50
|
+
});
|
|
51
|
+
return data.updateAdminBusiness;
|
|
52
|
+
}
|
|
53
|
+
} catch (e) {
|
|
54
|
+
console.error(`${message}: ${e}`);
|
|
55
|
+
toast.error('Error', {
|
|
56
|
+
id: notificationId,
|
|
57
|
+
description: message,
|
|
58
|
+
duration: 100_000,
|
|
59
|
+
closeButton: true,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
return void 0;
|
|
63
|
+
},
|
|
64
|
+
[mutate],
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
fetching,
|
|
69
|
+
updateAdminBusiness,
|
|
70
|
+
};
|
|
71
|
+
};
|