@redacto.io/consent-sdk-react 4.0.0 → 5.0.0

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.
Files changed (160) hide show
  1. package/CHANGELOG.md +13 -1
  2. package/LICENSE +176 -0
  3. package/dist/index.js +231 -96
  4. package/dist/index.mjs +231 -96
  5. package/dist/privacy-center.d.mts +649 -0
  6. package/dist/privacy-center.d.ts +649 -0
  7. package/dist/privacy-center.js +20824 -0
  8. package/dist/privacy-center.mjs +20789 -0
  9. package/package.json +47 -3
  10. package/src/RedactoNoticeConsent/RedactoNoticeConsent.tsx +6 -4
  11. package/src/RedactoNoticeConsent/api/index.ts +2 -0
  12. package/src/RedactoNoticeConsent/api/types.ts +2 -0
  13. package/src/RedactoNoticeConsent/components/DigiLockerCallback.tsx +128 -62
  14. package/src/RedactoNoticeConsent/language-codes.ts +97 -0
  15. package/src/RedactoNoticeConsentInline/RedactoNoticeConsentInline.tsx +0 -3
  16. package/src/RedactoNoticeConsentInline/api/index.ts +0 -1
  17. package/src/RedactoPrivacyCenter/PrivacyCenterActivityPage.tsx +19 -0
  18. package/src/RedactoPrivacyCenter/PrivacyCenterCaseDetailsPage.tsx +154 -0
  19. package/src/RedactoPrivacyCenter/PrivacyCenterConsentManagerPage.tsx +17 -0
  20. package/src/RedactoPrivacyCenter/PrivacyCenterFormPage.tsx +79 -0
  21. package/src/RedactoPrivacyCenter/PrivacyCenterHomePage.tsx +30 -0
  22. package/src/RedactoPrivacyCenter/PrivacyCenterLayout.tsx +173 -0
  23. package/src/RedactoPrivacyCenter/RedactoPrivacyCenter.tsx +55 -0
  24. package/src/RedactoPrivacyCenter/api/actions.ts +476 -0
  25. package/src/RedactoPrivacyCenter/api/client.ts +524 -0
  26. package/src/RedactoPrivacyCenter/api/config.ts +33 -0
  27. package/src/RedactoPrivacyCenter/api/fetcher.ts +181 -0
  28. package/src/RedactoPrivacyCenter/api/upload.ts +93 -0
  29. package/src/RedactoPrivacyCenter/assets/character.svg +31 -0
  30. package/src/RedactoPrivacyCenter/assets/fileAttach.svg +9 -0
  31. package/src/RedactoPrivacyCenter/assets/greenTick.svg +4 -0
  32. package/src/RedactoPrivacyCenter/assets/mail.svg +3 -0
  33. package/src/RedactoPrivacyCenter/assets/poweredByRedacto.svg +9 -0
  34. package/src/RedactoPrivacyCenter/assets/sentImg.svg +9 -0
  35. package/src/RedactoPrivacyCenter/assets/uploadFileIcon.svg +9 -0
  36. package/src/RedactoPrivacyCenter/components/ActivitiesList.tsx +272 -0
  37. package/src/RedactoPrivacyCenter/components/CaseDetails/AttachmentCard.tsx +38 -0
  38. package/src/RedactoPrivacyCenter/components/CaseDetails/ChatBubble.tsx +31 -0
  39. package/src/RedactoPrivacyCenter/components/CaseDetails/DocumentRequestCard.tsx +73 -0
  40. package/src/RedactoPrivacyCenter/components/CaseDetails/MessageComposer.tsx +87 -0
  41. package/src/RedactoPrivacyCenter/components/CaseDetails/MessageItem.tsx +95 -0
  42. package/src/RedactoPrivacyCenter/components/CaseDetails/MessagesTab.tsx +147 -0
  43. package/src/RedactoPrivacyCenter/components/CaseDetails/RequestDetailsTab.tsx +171 -0
  44. package/src/RedactoPrivacyCenter/components/CaseDetails/StatusEvent.tsx +23 -0
  45. package/src/RedactoPrivacyCenter/components/CaseDetails/useFileUpload.ts +116 -0
  46. package/src/RedactoPrivacyCenter/components/CaseDetails/useMessagePolling.ts +36 -0
  47. package/src/RedactoPrivacyCenter/components/CaseDetails/utils.ts +56 -0
  48. package/src/RedactoPrivacyCenter/components/CaseDetailsModal.tsx +469 -0
  49. package/src/RedactoPrivacyCenter/components/CaseHistory.tsx +426 -0
  50. package/src/RedactoPrivacyCenter/components/ConsentManager.tsx +732 -0
  51. package/src/RedactoPrivacyCenter/components/ConsentManagerColumns.tsx +238 -0
  52. package/src/RedactoPrivacyCenter/components/ConsentManagerConstants.ts +7 -0
  53. package/src/RedactoPrivacyCenter/components/ConsentManagerTableSkeleton.tsx +155 -0
  54. package/src/RedactoPrivacyCenter/components/DataRequest/CorrectionDataSection.tsx +189 -0
  55. package/src/RedactoPrivacyCenter/components/DataRequest/GrievanceDataSection.tsx +118 -0
  56. package/src/RedactoPrivacyCenter/components/DataRequest/NominationDataSection.tsx +66 -0
  57. package/src/RedactoPrivacyCenter/components/DataRequest/PurposeSelectionSection.tsx +304 -0
  58. package/src/RedactoPrivacyCenter/components/Form.tsx +1596 -0
  59. package/src/RedactoPrivacyCenter/components/GrievanceTable.tsx +174 -0
  60. package/src/RedactoPrivacyCenter/components/GrievanceTablePagination.tsx +337 -0
  61. package/src/RedactoPrivacyCenter/components/ModifyConsentModal.tsx +330 -0
  62. package/src/RedactoPrivacyCenter/components/Pagination.tsx +140 -0
  63. package/src/RedactoPrivacyCenter/components/PrivacyCenterLayout.tsx +304 -0
  64. package/src/RedactoPrivacyCenter/components/RequestSubmit.tsx +232 -0
  65. package/src/RedactoPrivacyCenter/components/SideMenuBarPC/SideBarPC.tsx +475 -0
  66. package/src/RedactoPrivacyCenter/components/SideMenuBarPC/SideMenuPC.tsx +408 -0
  67. package/src/RedactoPrivacyCenter/components/SideMenuBarPC/constants.tsx +42 -0
  68. package/src/RedactoPrivacyCenter/components/SideMenuBarPC/menuItemsPC.tsx +1 -0
  69. package/src/RedactoPrivacyCenter/components/SideMenuBarPC/types.ts +40 -0
  70. package/src/RedactoPrivacyCenter/components/SideMenuBarPC/utils.ts +38 -0
  71. package/src/RedactoPrivacyCenter/components/ThemeTransitionOverlay.tsx +85 -0
  72. package/src/RedactoPrivacyCenter/components/activitiesColumns.tsx +141 -0
  73. package/src/RedactoPrivacyCenter/components/caseHistoryColumns.tsx +159 -0
  74. package/src/RedactoPrivacyCenter/components/constant.ts +16 -0
  75. package/src/RedactoPrivacyCenter/components/types.ts +76 -0
  76. package/src/RedactoPrivacyCenter/components/utils.tsx +10 -0
  77. package/src/RedactoPrivacyCenter/config/routes.ts +9 -0
  78. package/src/RedactoPrivacyCenter/config/table.ts +25 -0
  79. package/src/RedactoPrivacyCenter/context/AuthContext.tsx +137 -0
  80. package/src/RedactoPrivacyCenter/context/BaseUrlContext.tsx +41 -0
  81. package/src/RedactoPrivacyCenter/context/LocaleContext.tsx +11 -0
  82. package/src/RedactoPrivacyCenter/context/NavigationContext.tsx +96 -0
  83. package/src/RedactoPrivacyCenter/context/OrganizationContext.tsx +30 -0
  84. package/src/RedactoPrivacyCenter/context/PageChromeContext.tsx +60 -0
  85. package/src/RedactoPrivacyCenter/context/theme.tsx +127 -0
  86. package/src/RedactoPrivacyCenter/context/types.ts +14 -0
  87. package/src/RedactoPrivacyCenter/lib/api.ts +566 -0
  88. package/src/RedactoPrivacyCenter/lib/consent-manager/utils.tsx +63 -0
  89. package/src/RedactoPrivacyCenter/lib/constants.ts +161 -0
  90. package/src/RedactoPrivacyCenter/lib/i18n.ts +81 -0
  91. package/src/RedactoPrivacyCenter/lib/locales.ts +105 -0
  92. package/src/RedactoPrivacyCenter/lib/queries.ts +134 -0
  93. package/src/RedactoPrivacyCenter/lib/types.ts +531 -0
  94. package/src/RedactoPrivacyCenter/lib/useCurrentLanguage.ts +37 -0
  95. package/src/RedactoPrivacyCenter/lib/utils.ts +626 -0
  96. package/src/RedactoPrivacyCenter/locales/as/translation.json +280 -0
  97. package/src/RedactoPrivacyCenter/locales/bho/translation.json +280 -0
  98. package/src/RedactoPrivacyCenter/locales/bn/translation.json +280 -0
  99. package/src/RedactoPrivacyCenter/locales/brx/translation.json +280 -0
  100. package/src/RedactoPrivacyCenter/locales/doi/translation.json +280 -0
  101. package/src/RedactoPrivacyCenter/locales/en/translation.json +255 -0
  102. package/src/RedactoPrivacyCenter/locales/gom/translation.json +280 -0
  103. package/src/RedactoPrivacyCenter/locales/gu/translation.json +280 -0
  104. package/src/RedactoPrivacyCenter/locales/hi/translation.json +280 -0
  105. package/src/RedactoPrivacyCenter/locales/kn/translation.json +280 -0
  106. package/src/RedactoPrivacyCenter/locales/ks/translation.json +280 -0
  107. package/src/RedactoPrivacyCenter/locales/mai/translation.json +280 -0
  108. package/src/RedactoPrivacyCenter/locales/ml/translation.json +280 -0
  109. package/src/RedactoPrivacyCenter/locales/mni-Mtei/translation.json +280 -0
  110. package/src/RedactoPrivacyCenter/locales/mr/translation.json +280 -0
  111. package/src/RedactoPrivacyCenter/locales/ne/translation.json +280 -0
  112. package/src/RedactoPrivacyCenter/locales/or/translation.json +280 -0
  113. package/src/RedactoPrivacyCenter/locales/pa/translation.json +280 -0
  114. package/src/RedactoPrivacyCenter/locales/sa/translation.json +280 -0
  115. package/src/RedactoPrivacyCenter/locales/sat/translation.json +280 -0
  116. package/src/RedactoPrivacyCenter/locales/sd/translation.json +280 -0
  117. package/src/RedactoPrivacyCenter/locales/ta/translation.json +280 -0
  118. package/src/RedactoPrivacyCenter/locales/te/translation.json +280 -0
  119. package/src/RedactoPrivacyCenter/locales/ur/translation.json +280 -0
  120. package/src/RedactoPrivacyCenter/styles/base.css +117 -0
  121. package/src/RedactoPrivacyCenter/styles/injectStyles.ts +1725 -0
  122. package/src/RedactoPrivacyCenter/styles/pcStyles.ts +813 -0
  123. package/src/RedactoPrivacyCenter/styles/responsive.ts +138 -0
  124. package/src/RedactoPrivacyCenter/styles/variables.css +133 -0
  125. package/src/RedactoPrivacyCenter/table/AdvancedTable.tsx +367 -0
  126. package/src/RedactoPrivacyCenter/table/AdvancedTablePagination.tsx +476 -0
  127. package/src/RedactoPrivacyCenter/table/index.ts +2 -0
  128. package/src/RedactoPrivacyCenter/types/images.d.ts +29 -0
  129. package/src/RedactoPrivacyCenter/ui/Footer.tsx +75 -0
  130. package/src/RedactoPrivacyCenter/ui/FormBlockWrapper.tsx +54 -0
  131. package/src/RedactoPrivacyCenter/ui/PCAccordion.tsx +93 -0
  132. package/src/RedactoPrivacyCenter/ui/PCActionIcon.tsx +47 -0
  133. package/src/RedactoPrivacyCenter/ui/PCAvatar.tsx +69 -0
  134. package/src/RedactoPrivacyCenter/ui/PCBadge.tsx +48 -0
  135. package/src/RedactoPrivacyCenter/ui/PCButton.tsx +77 -0
  136. package/src/RedactoPrivacyCenter/ui/PCCheckbox.tsx +55 -0
  137. package/src/RedactoPrivacyCenter/ui/PCCollapse.tsx +107 -0
  138. package/src/RedactoPrivacyCenter/ui/PCEmpty.tsx +35 -0
  139. package/src/RedactoPrivacyCenter/ui/PCInput.tsx +132 -0
  140. package/src/RedactoPrivacyCenter/ui/PCLoader.tsx +31 -0
  141. package/src/RedactoPrivacyCenter/ui/PCModal.tsx +106 -0
  142. package/src/RedactoPrivacyCenter/ui/PCPopover.tsx +173 -0
  143. package/src/RedactoPrivacyCenter/ui/PCSelect.tsx +387 -0
  144. package/src/RedactoPrivacyCenter/ui/PCTable.tsx +149 -0
  145. package/src/RedactoPrivacyCenter/ui/PCText.tsx +41 -0
  146. package/src/RedactoPrivacyCenter/ui/PCTextarea.tsx +43 -0
  147. package/src/RedactoPrivacyCenter/ui/PCTitle.tsx +37 -0
  148. package/src/RedactoPrivacyCenter/ui/PCTooltip.tsx +119 -0
  149. package/src/RedactoPrivacyCenter/ui/SimpleBar.tsx +25 -0
  150. package/src/RedactoPrivacyCenter/ui/StatusBadge.tsx +53 -0
  151. package/src/RedactoPrivacyCenter/ui/ThemeToggle.tsx +72 -0
  152. package/src/RedactoPrivacyCenter/ui/index.ts +18 -0
  153. package/src/RedactoPrivacyCenter/utils/cn.ts +28 -0
  154. package/src/RedactoPrivacyCenter/utils/date.ts +48 -0
  155. package/src/RedactoPrivacyCenter/utils/status.ts +111 -0
  156. package/src/RedactoPrivacyCenter/utils/toast.ts +130 -0
  157. package/src/privacy-center.ts +108 -0
  158. package/tsconfig.json +2 -0
  159. package/tsup.config.ts +16 -1
  160. package/.turbo/turbo-build.log +0 -21
@@ -0,0 +1,161 @@
1
+ import { RequestTypeEnum } from './types';
2
+ import { useTranslation } from 'react-i18next';
3
+ import { GRIEVANCE_TAB_IDS } from '../components/constant';
4
+ import { menuItemsPC } from '../components/SideMenuBarPC/constants';
5
+ import type { MenuItem } from '../components/SideMenuBarPC/types';
6
+ import type { InternalPage } from '../context/NavigationContext';
7
+ import type { DocumentRequestStatus, DocumentRequestStatusInfo } from './types';
8
+
9
+ export const useRequestTypeLabels = () => {
10
+ const { t } = useTranslation();
11
+
12
+ return {
13
+ [RequestTypeEnum.ACCESS]: t('access'),
14
+ [RequestTypeEnum.CORRECTION]: t('correction'),
15
+ [RequestTypeEnum.ERASURE]: t('erasure'),
16
+ [RequestTypeEnum.GRIEVANCE]: t('grievance'),
17
+ [RequestTypeEnum.NOMINATION]: t('nomination'),
18
+ } as Record<RequestTypeEnum, string>;
19
+ };
20
+
21
+ export const languageOptions = [
22
+ { value: 'en', label: 'English' },
23
+ { value: 'hi', label: 'हिन्दी (Hindi)' },
24
+ { value: 'te', label: 'తెలుగు (Telugu)' },
25
+ { value: 'mr', label: 'मराठी (Marathi)' },
26
+ { value: 'ta', label: 'தமிழ் (Tamil)' },
27
+ { value: 'ur', label: 'اردو (Urdu)' },
28
+ { value: 'gu', label: 'ગુજરાતી (Gujarati)' },
29
+ { value: 'kn', label: 'ಕನ್ನಡ (Kannada)' },
30
+ { value: 'ml', label: 'മലയാളം (Malayalam)' },
31
+ { value: 'pa', label: 'ਪੰਜਾਬੀ (Punjabi)' },
32
+ { value: 'or', label: 'ଓଡ଼ିଆ (Odia)' },
33
+ { value: 'as', label: 'অসমীয়া (Assamese)' },
34
+ { value: 'bn', label: 'বাংলা (Bengali)' },
35
+ { value: 'mai', label: 'मैथिली (Maithili)' },
36
+ { value: 'ne', label: 'नेपाली (Nepali)' },
37
+ { value: 'sd', label: 'سنڌي (Sindhi)' },
38
+ { value: 'doi', label: 'डोगरी (Dogri)' },
39
+ { value: 'mni-Mtei', label: 'ꯃꯩꯇꯩꯂꯣꯟ (Manipuri)' },
40
+ { value: 'gom', label: 'कोंकणी (Goan Konkani)' },
41
+ { value: 'sa', label: 'संस्कृतम् (Sanskrit)' },
42
+ { value: 'bho', label: 'भोजपुरी (Bhojpuri)' },
43
+ { value: 'brx', label: 'बड़ो (Bodo)' },
44
+ { value: 'ks', label: 'كٲشُر (Kashmiri)' },
45
+ { value: 'sat', label: 'ᱥᱟᱱᱛᱟᱲᱤ (Santali)' },
46
+ ];
47
+
48
+ export const useTimePeriodOptions = () => {
49
+ const { t } = useTranslation();
50
+
51
+ return [
52
+ { value: '1', label: t('today') },
53
+ { value: '7', label: t('last7Days') },
54
+ { value: '30', label: t('last30Days') },
55
+ { value: '90', label: t('last3Months') },
56
+ ];
57
+ };
58
+
59
+ export const useGrievanceTabs = () => {
60
+ const { t } = useTranslation();
61
+
62
+ return [
63
+ { id: GRIEVANCE_TAB_IDS.ALL, label: t('allRequests') },
64
+ { id: GRIEVANCE_TAB_IDS.PROCESSING, label: t('processing') },
65
+ { id: GRIEVANCE_TAB_IDS.COMPLETED, label: t('completed') },
66
+ { id: GRIEVANCE_TAB_IDS.REJECTED, label: t('rejected') },
67
+ ];
68
+ };
69
+
70
+ export type PageChromeConfig = {
71
+ titleKey: string;
72
+ descriptionKey: string;
73
+ };
74
+
75
+ export const PAGE_CHROME_BY_PAGE: Record<InternalPage, PageChromeConfig> = {
76
+ 'consent-manager': {
77
+ titleKey: 'manageConsent',
78
+ descriptionKey: 'manageConsentSubtitle',
79
+ },
80
+ form: {
81
+ titleKey: 'grievanceRequests',
82
+ descriptionKey: 'grievanceSubtitle',
83
+ },
84
+ activity: {
85
+ titleKey: 'activities',
86
+ descriptionKey: 'activitiesSubtitle',
87
+ },
88
+ 'case-details': {
89
+ titleKey: 'caseDetails',
90
+ descriptionKey: 'yourPrivacyCenter',
91
+ },
92
+ };
93
+
94
+ const HREF_TO_NAME_KEY: Record<string, string> = {
95
+ 'consent-manager': 'consentManager',
96
+ form: 'grievance',
97
+ activity: 'activity',
98
+ };
99
+
100
+ export const useMenuItemsPC = (): MenuItem[] => {
101
+ const { t } = useTranslation();
102
+ return menuItemsPC.map((item) => ({
103
+ ...item,
104
+ name: t((item.href && HREF_TO_NAME_KEY[item.href]) ?? item.name),
105
+ }));
106
+ };
107
+
108
+ // ─── Upload validation ────────────────────────────────────────────────────────
109
+
110
+ export const MAX_FILE_SIZE = 10 * 1024 * 1024; // 10 MB
111
+
112
+ export const ALLOWED_MIME_TYPES = [
113
+ 'application/pdf',
114
+ 'image/jpeg',
115
+ 'image/png',
116
+ 'image/webp',
117
+ 'application/msword',
118
+ 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
119
+ 'application/vnd.ms-excel',
120
+ 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
121
+ 'text/plain',
122
+ 'text/csv',
123
+ ];
124
+
125
+ // ─── Status colors ───────────────────────────────────────────────────────────
126
+
127
+ export const STATUS_COLORS = {
128
+ success: { color: '#16a34a', bg: '#f0fdf4', border: '#bbf7d0' },
129
+ error: { color: '#dc2626', bg: '#fef2f2', border: '#fecaca' },
130
+ warning: { color: '#d97706', bg: '#fffbeb', border: '#fde68a' },
131
+ info: { color: '#2563eb', bg: '#f8fbff', border: '#93c5fd' },
132
+ infoDark: '#1d4ed8',
133
+ infoBanner: { color: '#1d4ed8', bg: '#eff6ff', border: '#bfdbfe' },
134
+ } as const;
135
+
136
+ // ─── Document request ─────────────────────────────────────────────────────────
137
+
138
+ export const UPLOAD_ACTIVE_STATUSES: DocumentRequestStatus[] = ['pending', 'replacement_requested'];
139
+
140
+ export const DOCUMENT_REQUEST_STATUS_LABEL: Record<DocumentRequestStatus, DocumentRequestStatusInfo> = {
141
+ pending: { labelKey: 'docStatusPending', color: STATUS_COLORS.warning.color },
142
+ under_review: { labelKey: 'docStatusUnderReview', color: STATUS_COLORS.info.color },
143
+ approved: { labelKey: 'docStatusApproved', color: STATUS_COLORS.success.color },
144
+ rejected: { labelKey: 'docStatusRejected', color: STATUS_COLORS.error.color },
145
+ replacement_requested: { labelKey: 'docStatusReplacementRequested', color: STATUS_COLORS.warning.color },
146
+ };
147
+
148
+ // Activity columns constants
149
+ export const ACTIVITY_COLUMN_SIZES = {
150
+ TITLE: 220,
151
+ ACTIVITY_TYPE: 160,
152
+ DESCRIPTION: 320,
153
+ TIMESTAMP: 200,
154
+ } as const;
155
+
156
+ export const ACTIVITY_DESCRIPTION_TRUNCATE_LENGTH = 100;
157
+
158
+ export const ACTIVITY_DATE_FORMATS = {
159
+ DISPLAY: 'MMM D, YYYY [at] h:mm A',
160
+ TOOLTIP: 'MMMM D, YYYY [at] h:mm:ss A',
161
+ } as const;
@@ -0,0 +1,81 @@
1
+ import dayjs from 'dayjs';
2
+ import 'dayjs/locale/hi';
3
+ import 'dayjs/locale/te';
4
+ import 'dayjs/locale/mr';
5
+ import 'dayjs/locale/ta';
6
+ import 'dayjs/locale/ur';
7
+ import 'dayjs/locale/gu';
8
+ import 'dayjs/locale/kn';
9
+ import 'dayjs/locale/ml';
10
+ import 'dayjs/locale/pa-in';
11
+ import 'dayjs/locale/ne';
12
+ import 'dayjs/locale/sd';
13
+ import 'dayjs/locale/bn';
14
+ import 'dayjs/locale/gom-latn';
15
+ import i18n from 'i18next';
16
+ import LanguageDetector from 'i18next-browser-languagedetector';
17
+ import { initReactI18next } from 'react-i18next';
18
+ import translations from './locales';
19
+
20
+ // Map app language codes to dayjs locale IDs.
21
+ // Languages not listed here fall back to 'en'.
22
+ const dayjsLocaleMap: Record<string, string> = {
23
+ hi: 'hi',
24
+ te: 'te',
25
+ mr: 'mr',
26
+ ta: 'ta',
27
+ ur: 'ur',
28
+ gu: 'gu',
29
+ kn: 'kn',
30
+ ml: 'ml',
31
+ pa: 'pa-in',
32
+ ne: 'ne',
33
+ sd: 'sd',
34
+ bn: 'bn',
35
+ gom: 'gom-latn',
36
+ };
37
+
38
+ function syncDayjsLocale(lng: string) {
39
+ dayjs.locale(dayjsLocaleMap[lng] || 'en');
40
+ }
41
+
42
+ // Convert translations to i18next resources format
43
+ // i18next expects: { [language]: { [namespace]: { [key]: value } } }
44
+ const resources: Record<string, Record<string, any>> = {};
45
+ Object.keys(translations).forEach((lang) => {
46
+ resources[lang] = translations[lang];
47
+ });
48
+
49
+ i18n
50
+ .use(LanguageDetector)
51
+ .use(initReactI18next)
52
+ .init({
53
+ resources,
54
+ fallbackLng: 'en',
55
+ defaultNS: 'translation',
56
+ ns: ['translation'],
57
+ debug: false,
58
+ interpolation: {
59
+ escapeValue: false,
60
+ },
61
+ detection: {
62
+ order: ['sessionStorage', 'navigator', 'htmlTag'],
63
+ caches: ['sessionStorage'],
64
+ lookupSessionStorage: 'i18nextLng',
65
+ convertDetectedLanguage: (lng: string) => {
66
+ // Extract base language code (e.g. 'en-US' -> 'en') so it matches
67
+ // our supported language keys, but preserve script subtags like 'mni-Mtei'.
68
+ const base = lng.split('-')[0];
69
+ if (base && resources[base]) return base;
70
+ return lng;
71
+ },
72
+ },
73
+ react: {
74
+ useSuspense: false,
75
+ },
76
+ });
77
+
78
+ i18n.on('languageChanged', syncDayjsLocale);
79
+ syncDayjsLocale(i18n.language);
80
+
81
+ export default i18n;
@@ -0,0 +1,105 @@
1
+ // Static imports of all locale files for bundling
2
+ import enTranslation from '../locales/en/translation.json';
3
+ import asTranslation from '../locales/as/translation.json';
4
+ import bnTranslation from '../locales/bn/translation.json';
5
+ import bhoTranslation from '../locales/bho/translation.json';
6
+ import brxTranslation from '../locales/brx/translation.json';
7
+ import doiTranslation from '../locales/doi/translation.json';
8
+ import gomTranslation from '../locales/gom/translation.json';
9
+ import guTranslation from '../locales/gu/translation.json';
10
+ import hiTranslation from '../locales/hi/translation.json';
11
+ import knTranslation from '../locales/kn/translation.json';
12
+ import ksTranslation from '../locales/ks/translation.json';
13
+ import maiTranslation from '../locales/mai/translation.json';
14
+ import mlTranslation from '../locales/ml/translation.json';
15
+ import mniMteiTranslation from '../locales/mni-Mtei/translation.json';
16
+ import mrTranslation from '../locales/mr/translation.json';
17
+ import neTranslation from '../locales/ne/translation.json';
18
+ import orTranslation from '../locales/or/translation.json';
19
+ import paTranslation from '../locales/pa/translation.json';
20
+ import saTranslation from '../locales/sa/translation.json';
21
+ import satTranslation from '../locales/sat/translation.json';
22
+ import sdTranslation from '../locales/sd/translation.json';
23
+ import taTranslation from '../locales/ta/translation.json';
24
+ import teTranslation from '../locales/te/translation.json';
25
+ import urTranslation from '../locales/ur/translation.json';
26
+
27
+ const activityFetchErrorTranslations: Record<string, string> = {
28
+ en: 'Failed to fetch activity data',
29
+ as: 'কাৰ্যকলাপৰ তথ্য আনিবলৈ ব্যৰ্থ',
30
+ bn: 'কার্যকলাপের ডেটা আনতে ব্যর্থ',
31
+ bho: 'गतिविधि डेटा लावे में विफल',
32
+ brx: 'खामानि डाटा लाङो दिहुनायाव असफल',
33
+ doi: 'गतिविधि डेटा लावै मे असफल',
34
+ gom: 'क्रियाकलाप डेटा आणपांत अयशस्वी',
35
+ gu: 'પ્રવૃત્તિ ડેટા મેળવવામાં નિષ્ફળ',
36
+ hi: 'गतिविधि डेटा लाने में विफल',
37
+ kn: 'ಚಟುವಟಿಕೆ ಡೇಟಾವನ್ನು ತರಲು ವಿಫಲ',
38
+ ks: 'سرگرمی ڈیٹا حاصل کرنے میں ناکام',
39
+ mai: 'गतिविधि डेटा लावै मे असफल',
40
+ ml: 'പ്രവർത്തന ഡാറ്റ ലഭ്യമാക്കുന്നതിൽ പരാജയപ്പെട്ടു',
41
+ 'mni-Mtei': 'ꯈꯨꯗꯝꯕꯤꯠ ꯗꯦꯇꯥ ꯐꯪꯉꯕꯗ ꯌꯥꯝꯅꯥ ꯋꯥꯏ꯫',
42
+ mr: 'क्रियाकलाप डेटा आणण्यात अयशस्वी',
43
+ ne: 'गतिविधि डेटा ल्याउन असफल',
44
+ or: 'କାର୍ଯ୍ୟକଳାପ ତଥ୍ୟ ଆଣିବାରେ ବିଫଳ',
45
+ pa: 'ਗਤੀਵਿਧੀ ਡਾਟਾ ਲਿਆਉਣ ਵਿੱਚ ਅਸਫਲ',
46
+ sa: 'क्रियाकलाप-दत्तांशम् आने विफलम्',
47
+ sat: 'ᱠᱟᱹᱢᱤ ᱰᱟᱴᱟ ᱟᱹᱜᱩ ᱨᱮ ᱵᱤᱯᱚᱠ',
48
+ sd: 'سرگرمي جي ڊيٽا حاصل ڪرڻ ۾ ناڪام',
49
+ ta: 'செயல்பாட்டு தரவை பெற முடியவில்லை',
50
+ te: 'కార్యకలాప డేటాను తెచ్చుకోవడం విఫలమైంది',
51
+ ur: 'سرگرمی کا ڈیٹا حاصل کرنے میں ناکام',
52
+ };
53
+
54
+ function withSharedActivityErrors(
55
+ language: string,
56
+ translation: Record<string, any>
57
+ ) {
58
+ return {
59
+ ...translation,
60
+ failedToFetchActivityData:
61
+ activityFetchErrorTranslations[language] ??
62
+ activityFetchErrorTranslations.en,
63
+ };
64
+ }
65
+
66
+ // Map of language codes to translation objects
67
+ const translations: Record<string, Record<string, any>> = {
68
+ en: { translation: withSharedActivityErrors('en', enTranslation) },
69
+ as: { translation: withSharedActivityErrors('as', asTranslation) },
70
+ bn: { translation: withSharedActivityErrors('bn', bnTranslation) },
71
+ bho: { translation: withSharedActivityErrors('bho', bhoTranslation) },
72
+ brx: { translation: withSharedActivityErrors('brx', brxTranslation) },
73
+ doi: { translation: withSharedActivityErrors('doi', doiTranslation) },
74
+ gom: { translation: withSharedActivityErrors('gom', gomTranslation) },
75
+ gu: { translation: withSharedActivityErrors('gu', guTranslation) },
76
+ hi: { translation: withSharedActivityErrors('hi', hiTranslation) },
77
+ kn: { translation: withSharedActivityErrors('kn', knTranslation) },
78
+ ks: { translation: withSharedActivityErrors('ks', ksTranslation) },
79
+ mai: { translation: withSharedActivityErrors('mai', maiTranslation) },
80
+ ml: { translation: withSharedActivityErrors('ml', mlTranslation) },
81
+ 'mni-Mtei': { translation: withSharedActivityErrors('mni-Mtei', mniMteiTranslation) },
82
+ mr: { translation: withSharedActivityErrors('mr', mrTranslation) },
83
+ ne: { translation: withSharedActivityErrors('ne', neTranslation) },
84
+ or: { translation: withSharedActivityErrors('or', orTranslation) },
85
+ pa: { translation: withSharedActivityErrors('pa', paTranslation) },
86
+ sa: { translation: withSharedActivityErrors('sa', saTranslation) },
87
+ sat: { translation: withSharedActivityErrors('sat', satTranslation) },
88
+ sd: { translation: withSharedActivityErrors('sd', sdTranslation) },
89
+ ta: { translation: withSharedActivityErrors('ta', taTranslation) },
90
+ te: { translation: withSharedActivityErrors('te', teTranslation) },
91
+ ur: { translation: withSharedActivityErrors('ur', urTranslation) },
92
+ };
93
+
94
+ export function getTranslation(language: string, namespace: string) {
95
+ const langTranslations = translations[language];
96
+ if (!langTranslations) {
97
+ // Fallback to English if language not found
98
+ const fallback = translations.en?.[namespace];
99
+ return fallback || {};
100
+ }
101
+ const translation = langTranslations[namespace];
102
+ return translation || {};
103
+ }
104
+
105
+ export default translations;
@@ -0,0 +1,134 @@
1
+ import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
2
+ import {
3
+ fetchCaseHistory,
4
+ getCaseMessages,
5
+ sendCaseMessage,
6
+ uploadCaseDocument,
7
+ submitDocumentForRequest,
8
+ type AuthContext,
9
+ } from './api';
10
+ import { useBaseUrl } from '../context/BaseUrlContext';
11
+ import { useCurrentLanguage } from './useCurrentLanguage';
12
+ import type { SendCaseMessageInput, SubmitDocumentForRequestInput } from './types';
13
+
14
+ export const useCaseHistory = (
15
+ organizationId: string | undefined,
16
+ workspaceId: string | undefined,
17
+ contact: string | undefined,
18
+ authContext?: AuthContext
19
+ ) => {
20
+ const { consentClient } = useBaseUrl();
21
+ // Include accessToken in queryKey so queries refetch when tokens change
22
+ // This ensures data is refetched with new tokens after refresh
23
+ const accessToken = authContext?.accessToken;
24
+ const { currentLanguage, langParam } = useCurrentLanguage();
25
+
26
+ return useQuery({
27
+ queryKey: ['caseHistory', organizationId, workspaceId, contact, accessToken, currentLanguage],
28
+ queryFn: async () => {
29
+ if (!organizationId || !workspaceId || !contact) {
30
+ return [];
31
+ }
32
+ const response = await fetchCaseHistory(organizationId, workspaceId, contact, undefined, undefined, authContext, consentClient, langParam);
33
+ return response?.data || [];
34
+ },
35
+ enabled: !!organizationId && !!workspaceId && !!contact && !!consentClient,
36
+ retry: 1,
37
+ });
38
+ };
39
+
40
+ // ─── Case Communication ──────────────────────────────────────────────────────
41
+
42
+ export const useCaseMessages = (
43
+ organizationId: string | undefined,
44
+ workspaceId: string | undefined,
45
+ caseUuid: string | undefined,
46
+ authContext?: AuthContext
47
+ ) => {
48
+ const { consentClient } = useBaseUrl();
49
+ const accessToken = authContext?.accessToken;
50
+
51
+ return useQuery({
52
+ queryKey: ['caseMessages', organizationId, workspaceId, caseUuid, accessToken],
53
+ queryFn: async () => {
54
+ if (!organizationId || !workspaceId || !caseUuid) return [];
55
+ const result = await getCaseMessages(organizationId, workspaceId, caseUuid, authContext, consentClient);
56
+ if (result === null) throw new Error('Failed to fetch case messages');
57
+ return result;
58
+ },
59
+ // Sort ascending (oldest → newest) regardless of server return order.
60
+ // ISO 8601 strings sort correctly as strings, so we fall back to that
61
+ // if Date parsing fails (avoids NaN comparisons leaving order undefined).
62
+ select: (data) =>
63
+ [...data].sort((a, b) => {
64
+ const ta = new Date(a.created_at).getTime();
65
+ const tb = new Date(b.created_at).getTime();
66
+ if (isNaN(ta) || isNaN(tb)) return a.created_at < b.created_at ? -1 : 1;
67
+ return ta - tb;
68
+ }),
69
+ enabled: !!organizationId && !!workspaceId && !!caseUuid && !!consentClient,
70
+ retry: 1,
71
+ });
72
+ };
73
+
74
+ export const useSendCaseMessage = (
75
+ organizationId: string | undefined,
76
+ workspaceId: string | undefined,
77
+ caseUuid: string | undefined,
78
+ authContext?: AuthContext
79
+ ) => {
80
+ const { consentClient } = useBaseUrl();
81
+ const queryClient = useQueryClient();
82
+
83
+ return useMutation({
84
+ mutationFn: async ({ body, documentUuids }: SendCaseMessageInput) => {
85
+ if (!organizationId || !workspaceId || !caseUuid) throw new Error('Missing params');
86
+ const result = await sendCaseMessage(organizationId, workspaceId, caseUuid, body, documentUuids, authContext, consentClient);
87
+ if (result === null) throw new Error('Send case message failed');
88
+ return result;
89
+ },
90
+ onSuccess: () => {
91
+ queryClient.invalidateQueries({ queryKey: ['caseMessages', organizationId, workspaceId, caseUuid] });
92
+ },
93
+ });
94
+ };
95
+
96
+ export const useUploadCaseDocument = (
97
+ organizationId: string | undefined,
98
+ workspaceId: string | undefined,
99
+ caseUuid: string | undefined,
100
+ authContext?: AuthContext
101
+ ) => {
102
+ const { consentClient } = useBaseUrl();
103
+
104
+ return useMutation({
105
+ mutationFn: async (file: File) => {
106
+ if (!organizationId || !workspaceId || !caseUuid) throw new Error('Missing params');
107
+ const result = await uploadCaseDocument(organizationId, workspaceId, caseUuid, file, authContext, consentClient);
108
+ if (result === null) throw new Error('Upload case document failed');
109
+ return result;
110
+ },
111
+ });
112
+ };
113
+
114
+ export const useSubmitDocumentForRequest = (
115
+ organizationId: string | undefined,
116
+ workspaceId: string | undefined,
117
+ caseUuid: string | undefined,
118
+ authContext?: AuthContext
119
+ ) => {
120
+ const { consentClient } = useBaseUrl();
121
+ const queryClient = useQueryClient();
122
+
123
+ return useMutation({
124
+ mutationFn: async ({ requestEventUuid, documentUuid, body }: SubmitDocumentForRequestInput) => {
125
+ if (!organizationId || !workspaceId || !caseUuid) throw new Error('Missing params');
126
+ const result = await submitDocumentForRequest(organizationId, workspaceId, caseUuid, requestEventUuid, documentUuid, body, authContext, consentClient);
127
+ if (result === null) throw new Error('Submit document for request failed');
128
+ return result;
129
+ },
130
+ onSuccess: () => {
131
+ queryClient.invalidateQueries({ queryKey: ['caseMessages', organizationId, workspaceId, caseUuid] });
132
+ },
133
+ });
134
+ };