@accounter/client 0.0.8-alpha-20251022132444-51d3ebadb2849ea323e03b88c735cdca4f91db7d → 0.0.8-alpha-20251022162652-6facbcde08fdda0fb354ba7105432df320367509
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 +18 -1
- package/dist/assets/{index-BexxGuN6.js → index-D312yRtG.js} +297 -292
- package/dist/assets/{index.es-CWwhWGxX.js → index.es-Bh5tff8R.js} +1 -1
- package/dist/index.html +1 -1
- package/package.json +1 -1
- package/src/components/business/admin-business-section.tsx +290 -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/helpers/dates.ts +2 -32
- package/src/hooks/use-update-admin-business.ts +71 -0
package/src/helpers/dates.ts
CHANGED
|
@@ -1,37 +1,7 @@
|
|
|
1
1
|
import { format } from 'date-fns';
|
|
2
2
|
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
return undefined;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
const numMonth = Number(month);
|
|
9
|
-
if (Number.isNaN(numMonth) || numMonth < 0 || numMonth > 12) {
|
|
10
|
-
return undefined;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
if (month.length === 1) {
|
|
14
|
-
return `0${month}`;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return month;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export const parseYear = (year?: string): string | undefined => {
|
|
21
|
-
if (!year) {
|
|
22
|
-
return undefined;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const numYear = Number(year);
|
|
26
|
-
if (Number.isNaN(numYear) || numYear < 2000 || numYear > 2030) {
|
|
27
|
-
return undefined;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return year;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export function hashDateFormat(date: Date): string {
|
|
34
|
-
return format(new Date(date), 'yyyy/MM/dd');
|
|
3
|
+
export function formatTimelessDateString(date: Date): TimelessDateString {
|
|
4
|
+
return format(date, 'yyyy-MM-dd') as TimelessDateString;
|
|
35
5
|
}
|
|
36
6
|
|
|
37
7
|
type addZero<T> = T | 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
|
+
};
|