@jsb188/mday-web 1.1.2

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,150 @@
1
+ import { formatCurrency } from '@jsb188/app/utils/number.ts';
2
+ import type { OrganizationOperationEnum } from '@jsb188/mday/types/organization.d.ts';
3
+ import { COMMON_ICON_NAMES } from '@jsb188/react-web/svgs/Icon';
4
+
5
+ import { matchIconName } from './log-web.helpers.ts';
6
+ import {
7
+ ARABLE_ICON_MATCHERS,
8
+ FARMERS_MARKET_ICON_MATCHERS,
9
+ FOOD_MANUFACTURING_DEFAULT_ICON,
10
+ FOOD_MANUFACTURING_ICON_MATCHERS,
11
+ } from './log-web.icons.ts';
12
+
13
+ /*
14
+ * Select a crop icon by tier and specificity, falling back to notes only when the crop has no match.
15
+ */
16
+ export function getIconNameForArable(crop?: string | undefined, note?: string | null, defaultIcon?: string): string {
17
+ return matchIconName(ARABLE_ICON_MATCHERS, crop) || matchIconName(ARABLE_ICON_MATCHERS, note) || defaultIcon || 'seedling';
18
+ }
19
+
20
+ /*
21
+ * Select a market item icon using the same matching rules and item-before-notes fallback as crops.
22
+ */
23
+ export function getIconNameForFarmersMarket(purchasedItem?: string | null, note?: string | null, defaultIcon?: string): string {
24
+ return (
25
+ matchIconName(FARMERS_MARKET_ICON_MATCHERS, purchasedItem) ||
26
+ matchIconName(FARMERS_MARKET_ICON_MATCHERS, note) ||
27
+ defaultIcon ||
28
+ 'farmers-market-kiosk'
29
+ );
30
+ }
31
+
32
+ /*
33
+ * Select a food manufacturing icon from the item, then notes, defaulting to meal-can unless the caller supplies a fallback.
34
+ */
35
+ export function getIconNameForFoodManufacturing(item?: string | null, note?: string | null, defaultIcon?: string): string {
36
+ return (
37
+ matchIconName(FOOD_MANUFACTURING_ICON_MATCHERS, item) ||
38
+ matchIconName(FOOD_MANUFACTURING_ICON_MATCHERS, note) ||
39
+ defaultIcon ||
40
+ FOOD_MANUFACTURING_DEFAULT_ICON
41
+ );
42
+ }
43
+
44
+ /**
45
+ * Get the icon name for grower network logs
46
+ * @param _item - The log item text
47
+ * @param _note - Additional note text
48
+ * @param _defaultIcon - The default icon to return if no match is found
49
+ * @returns The icon name or a default icon if no match is found
50
+ */
51
+
52
+ export function getIconNameForGrowerNetwork(_item?: string | null, _note?: string | null, _defaultIcon?: string): string {
53
+ return 'circle';
54
+ }
55
+
56
+ /**
57
+ * Get any icon name for any word
58
+ */
59
+
60
+ export function getIconNameForWord(decidingWord: any, text1: string, text2?: string | null, defaultIcon?: string) {
61
+ switch (decidingWord) {
62
+ case 'ARABLE':
63
+ return getIconNameForArable(text1, text2, defaultIcon);
64
+ case 'FARMERS_MARKET':
65
+ return getIconNameForFarmersMarket(text1, text2, defaultIcon);
66
+ case 'FOOD_MANUFACTURING':
67
+ return getIconNameForFoodManufacturing(text1, text2, defaultIcon);
68
+ case 'GROWER_NETWORK':
69
+ return getIconNameForGrowerNetwork(text1, text2, defaultIcon);
70
+ default:
71
+ }
72
+ return 'circle';
73
+ }
74
+
75
+ /**
76
+ * Return the shared icon for one log activity-group key.
77
+ */
78
+ export function getLogActivityGroupIconName(activityGroup?: string | null) {
79
+ return COMMON_ICON_NAMES[activityGroup || 'UNKNOWN'] || COMMON_ICON_NAMES.UNKNOWN;
80
+ }
81
+
82
+ /**
83
+ * Get an operation's text-matched icon. Food manufacturing defaults to meal-can for unmatched text;
84
+ * other non-legacy operations use activity, group, or caller-provided fallback icons.
85
+ * @param details - GraphQL log details object
86
+ * @param defaultIcon - The default icon to return if no match is found
87
+ * @param orgOperation - The organization's operation; when omitted, the operation is inferred from the log type (legacy behavior)
88
+ * @returns The icon name or a default icon if no match is found
89
+ */
90
+
91
+ export function getIconNameForLog(
92
+ details: any,
93
+ preferActivityText?: boolean,
94
+ defaultIcon_?: string,
95
+ orgOperation?: OrganizationOperationEnum | null,
96
+ ) {
97
+ if (orgOperation === 'FOOD_MANUFACTURING') {
98
+ return getIconNameForFoodManufacturing(
99
+ preferActivityText ? details.activity : details.item,
100
+ preferActivityText ? `${details.title || ''} ${details.notes || ''}` : details.notes,
101
+ defaultIcon_,
102
+ );
103
+ }
104
+
105
+ // Non-legacy operations can share group keys with legacy operations (e.g. OPERATION), so only the org's operation can tell them apart
106
+ if (orgOperation && !['ARABLE', 'FARMERS_MARKET', 'GROWER_NETWORK'].includes(orgOperation)) {
107
+ return COMMON_ICON_NAMES[details.activity] || COMMON_ICON_NAMES[details.type] || defaultIcon_ || COMMON_ICON_NAMES.logs;
108
+ }
109
+
110
+ // "crop" is deprecation support -- it should be "item" going forward
111
+ const text1 = preferActivityText ? details.activity : details.item;
112
+ const text2 = preferActivityText ? details.title + ' ' + details.notes : details.notes;
113
+ // @ts-ignore - allow dynamic key access
114
+ const defaultIcon = (preferActivityText && COMMON_ICON_NAMES[details.activity]) || defaultIcon_;
115
+
116
+ // console.log('defaultIcon', preferActivityText, details.activity, defaultIcon);
117
+
118
+ const operation = String(details.type || '').startsWith('MARKET_')
119
+ ? 'FARMERS_MARKET'
120
+ : ['WORKER_PRACTICE', 'PRODUCTION_INPUT'].includes(details.type)
121
+ ? 'GROWER_NETWORK'
122
+ : 'ARABLE';
123
+
124
+ return getIconNameForWord(operation, text1, text2, defaultIcon);
125
+ }
126
+
127
+ /**
128
+ * Get title for log
129
+ */
130
+
131
+ export function getTitleForLog(details: any): string {
132
+ switch (details.type) {
133
+ case 'MARKET_RECEIPT':
134
+ {
135
+ // Check if text from values is short, else rely on the AI summary
136
+ const valuesText = (details.values || [])
137
+ .map((item: any) => {
138
+ return `${item.label} ${item.value ? formatCurrency(item.value, false) : ''}`.trim();
139
+ })
140
+ .join(', ');
141
+
142
+ if (valuesText.length <= 40) {
143
+ return valuesText;
144
+ }
145
+ }
146
+ break;
147
+ default:
148
+ }
149
+ return details.item;
150
+ }
@@ -0,0 +1,154 @@
1
+ import type { OrganizationOperationEnum } from '@jsb188/mday/types/organization.d.ts';
2
+ import { COMMON_ICON_NAMES } from '@jsb188/react-web/svgs/Icon';
3
+
4
+ interface OperationPageDefinition {
5
+ slug: string;
6
+ titleKey: string;
7
+ metaTitleKey: string;
8
+ descriptionKey: string;
9
+ navigationTitleKey: string;
10
+ iconName: string;
11
+ allowedOperations: readonly OrganizationOperationEnum[];
12
+ }
13
+
14
+ export const OPERATION_PAGES = {
15
+ greenhouse: {
16
+ slug: 'greenhouse',
17
+ titleKey: 'log.greenhouse_seeding',
18
+ metaTitleKey: 'log.greenhouse_seeding',
19
+ descriptionKey: 'app.meta_greenhouse_desc',
20
+ navigationTitleKey: 'log.greenhouse_seeding',
21
+ iconName: COMMON_ICON_NAMES.GREENHOUSE_SEEDING,
22
+ allowedOperations: ['ARABLE'],
23
+ },
24
+ seeding: {
25
+ slug: 'seeding',
26
+ titleKey: 'log.seeding',
27
+ metaTitleKey: 'log.seeding',
28
+ descriptionKey: 'app.meta_seeding_desc',
29
+ navigationTitleKey: 'log.seeding',
30
+ iconName: COMMON_ICON_NAMES.seeding,
31
+ allowedOperations: ['ARABLE'],
32
+ },
33
+ transplanting: {
34
+ slug: 'transplanting',
35
+ titleKey: 'log.transplanting',
36
+ metaTitleKey: 'log.transplanting',
37
+ descriptionKey: 'app.meta_transplanting_desc',
38
+ navigationTitleKey: 'log.transplanting',
39
+ iconName: COMMON_ICON_NAMES.transplanting,
40
+ allowedOperations: ['ARABLE'],
41
+ },
42
+ 'field-work': {
43
+ slug: 'field-work',
44
+ titleKey: 'log.field_work',
45
+ metaTitleKey: 'log.field_work',
46
+ descriptionKey: 'app.meta_field_work_desc',
47
+ navigationTitleKey: 'log.field_work',
48
+ iconName: COMMON_ICON_NAMES.field_work,
49
+ allowedOperations: ['ARABLE'],
50
+ },
51
+ harvested: {
52
+ slug: 'harvested',
53
+ titleKey: 'log.harvested',
54
+ metaTitleKey: 'log.harvested',
55
+ descriptionKey: 'app.meta_harvested_desc',
56
+ navigationTitleKey: 'log.harvested',
57
+ iconName: COMMON_ICON_NAMES.harvest,
58
+ allowedOperations: ['ARABLE'],
59
+ },
60
+ 'post-harvest': {
61
+ slug: 'post-harvest',
62
+ titleKey: 'log.post_harvest',
63
+ metaTitleKey: 'log.post_harvest',
64
+ descriptionKey: 'app.meta_post_harvest_desc',
65
+ navigationTitleKey: 'log.post_harvest',
66
+ iconName: COMMON_ICON_NAMES.post_harvest,
67
+ allowedOperations: ['ARABLE'],
68
+ },
69
+ purchases: {
70
+ slug: 'purchases',
71
+ titleKey: 'log.purchases',
72
+ metaTitleKey: 'log.purchases',
73
+ descriptionKey: 'app.meta_purchases_desc',
74
+ navigationTitleKey: 'log.purchases',
75
+ iconName: COMMON_ICON_NAMES.invoice,
76
+ allowedOperations: ['ARABLE'],
77
+ },
78
+ orders: {
79
+ slug: 'orders',
80
+ titleKey: 'c.sales_orders',
81
+ metaTitleKey: 'c.sales_orders',
82
+ descriptionKey: 'app.meta_orders_desc',
83
+ navigationTitleKey: 'c.sales_orders',
84
+ iconName: COMMON_ICON_NAMES.receipt,
85
+ allowedOperations: ['ARABLE'],
86
+ },
87
+ temperature: {
88
+ slug: 'temperature',
89
+ titleKey: 'log.temperature',
90
+ metaTitleKey: 'log.temperature',
91
+ descriptionKey: 'app.meta_temperature_desc',
92
+ navigationTitleKey: 'log.temperature',
93
+ iconName: COMMON_ICON_NAMES.temperature,
94
+ allowedOperations: ['FOOD_MANUFACTURING'],
95
+ },
96
+ inspections: {
97
+ slug: 'inspections',
98
+ titleKey: 'log.inspections',
99
+ metaTitleKey: 'log.inspections',
100
+ descriptionKey: 'app.meta_inspections_desc',
101
+ navigationTitleKey: 'log.inspections',
102
+ iconName: COMMON_ICON_NAMES.SITE_INSPECTION,
103
+ allowedOperations: ['FOOD_MANUFACTURING'],
104
+ },
105
+ receipts: {
106
+ slug: 'receipts',
107
+ titleKey: 'c.receipts',
108
+ metaTitleKey: 'c.market_receipts',
109
+ descriptionKey: 'app.meta_receipts_desc',
110
+ navigationTitleKey: 'c.market_receipts',
111
+ iconName: COMMON_ICON_NAMES.market_receipt,
112
+ allowedOperations: ['FARMERS_MARKET'],
113
+ },
114
+ vendors: {
115
+ slug: 'vendors',
116
+ titleKey: 'c.vendors',
117
+ metaTitleKey: 'c.vendors',
118
+ descriptionKey: 'app.meta_vendors_desc',
119
+ navigationTitleKey: 'c.vendors',
120
+ iconName: COMMON_ICON_NAMES.shop_vendor,
121
+ allowedOperations: ['FARMERS_MARKET'],
122
+ },
123
+ growers: {
124
+ slug: 'growers',
125
+ titleKey: 'org.growers',
126
+ metaTitleKey: 'org.growers',
127
+ descriptionKey: 'app.meta_growers_desc',
128
+ navigationTitleKey: 'org.growers',
129
+ iconName: COMMON_ICON_NAMES.growers,
130
+ allowedOperations: ['GROWER_NETWORK'],
131
+ },
132
+ } as const satisfies Record<string, OperationPageDefinition>;
133
+
134
+ export type OperationPageSlug = keyof typeof OPERATION_PAGES;
135
+ export type OperationPageMetadata = (typeof OPERATION_PAGES)[OperationPageSlug];
136
+
137
+ /*
138
+ * Return operation-page metadata only for an exact registered slug.
139
+ */
140
+ export function getOperationPageMetadata(page: string | null | undefined): OperationPageMetadata | null {
141
+ return page && Object.hasOwn(OPERATION_PAGES, page) ? OPERATION_PAGES[page as OperationPageSlug] : null;
142
+ }
143
+
144
+ /*
145
+ * Resolve an exact page slug only when it supports the organization's operation.
146
+ */
147
+ export function resolveOperationPage(
148
+ page: string | null | undefined,
149
+ operation: OrganizationOperationEnum | null | undefined,
150
+ ): OperationPageMetadata | null {
151
+ const metadata = getOperationPageMetadata(page);
152
+
153
+ return metadata?.allowedOperations.some((allowedOperation) => allowedOperation === operation) ? metadata : null;
154
+ }
@@ -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
+ }