@jsb188/mday-web 1.1.8 → 1.1.11

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.
@@ -0,0 +1,67 @@
1
+ import i18n from '@jsb188/app/i18n/index.ts';
2
+ import type {
3
+ OrganizationGQL,
4
+ OrganizationOperationEnum,
5
+ } from '@jsb188/mday/types/organization.d.ts';
6
+ import { COMMON_ICON_NAMES } from '@jsb188/react-web/svgs/Icon';
7
+
8
+ /*
9
+ * Get the icon name for one organization operation.
10
+ */
11
+ export function getOrgOperationIconName(
12
+ operation?: OrganizationOperationEnum | string | null,
13
+ ): string {
14
+ return (operation && COMMON_ICON_NAMES[operation]) || COMMON_ICON_NAMES.info;
15
+ }
16
+
17
+ /*
18
+ * Get the <SimpleLabel> preset for one organization role badge. Owners and
19
+ * admins get colored outlines; every other role falls back to a neutral outline.
20
+ */
21
+ export function getOrgRoleLabelPreset(
22
+ role?: string | null,
23
+ ): 'outline_main' | 'outline_primary' | 'outline_secondary' | 'outline' {
24
+ switch (role) {
25
+ case 'OWNER':
26
+ return 'outline_primary';
27
+ case 'ADMIN':
28
+ return 'outline_secondary';
29
+ default:
30
+ return 'outline';
31
+ }
32
+ }
33
+
34
+ /*
35
+ * Get all title icons for organization/vendor.
36
+ */
37
+ export function getTitleIconsForOrganization(
38
+ org: OrganizationGQL,
39
+ showIconsRule: Record<string, boolean> = {},
40
+ ) {
41
+ const { operation, compliance } = org;
42
+ const titleIcons = [];
43
+
44
+ if (operation && showIconsRule.operation !== false) {
45
+ titleIcons.push({
46
+ iconName: getOrgOperationIconName(operation),
47
+ tooltipText: i18n.t(`org.type.${operation}`),
48
+ });
49
+ }
50
+
51
+ if (compliance?.length && showIconsRule.compliance !== false) {
52
+ const today = new Date();
53
+ const todayCalDate = today.toISOString().split('T')[0];
54
+ const notExpired = compliance.filter(
55
+ (item: any) => item.expirationDate && item.expirationDate > todayCalDate,
56
+ );
57
+
58
+ if (notExpired.length > 0) {
59
+ titleIcons.push({
60
+ iconName: 'document-license',
61
+ tooltipText: notExpired.map((item: any) => item.name).join(', '),
62
+ });
63
+ }
64
+ }
65
+
66
+ return titleIcons;
67
+ }