@cuemath/web-utils 0.0.1-beta.0 → 0.0.1-beta.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.
Files changed (56) hide show
  1. package/.eslintignore +2 -0
  2. package/.husky/pre-commit +1 -0
  3. package/.huskyrc +5 -0
  4. package/.lintstagedrc.yml +5 -0
  5. package/dist/index.js +3 -0
  6. package/lerna.json +8 -0
  7. package/package-lock.json +7528 -0
  8. package/package.json +22 -5
  9. package/src/constants/country/index.ts +4 -0
  10. package/src/constants/country/iso-country-code.ts +248 -0
  11. package/src/constants/date-time/e-cna-international-timezones.ts +157 -0
  12. package/src/constants/date-time/index.ts +78 -0
  13. package/src/constants/e-cna/index.ts +502 -0
  14. package/src/constants/index.ts +2 -0
  15. package/src/cookie/index.ts +59 -1
  16. package/src/date-time-helper/index.ts +363 -0
  17. package/src/e-cna/flow/aggregator.ts +6 -0
  18. package/src/e-cna/flow/index.ts +1 -0
  19. package/src/e-cna/flow/variants/default.ts +40 -0
  20. package/src/e-cna/flow/variants/index.ts +1 -0
  21. package/src/e-cna/index.ts +264 -0
  22. package/src/e-cna/slides/child_hobbies/index.ts +1 -0
  23. package/src/e-cna/slides/child_hobbies/variants.ts +13 -0
  24. package/src/e-cna/slides/child_personality/index.ts +1 -0
  25. package/src/e-cna/slides/child_personality/variants.ts +12 -0
  26. package/src/e-cna/slides/grade/index.ts +1 -0
  27. package/src/e-cna/slides/grade/variants.ts +27 -0
  28. package/src/e-cna/slides/index.ts +16 -0
  29. package/src/e-cna/slides/intro/index.ts +1 -0
  30. package/src/e-cna/slides/intro/variants.ts +7 -0
  31. package/src/e-cna/slides/key_need_l1/index.ts +1 -0
  32. package/src/e-cna/slides/key_need_l1/variants.ts +44 -0
  33. package/src/e-cna/slides/key_need_l2/index.ts +1 -0
  34. package/src/e-cna/slides/key_need_l2/variants.ts +143 -0
  35. package/src/e-cna/slides/key_need_l3/index.ts +1 -0
  36. package/src/e-cna/slides/key_need_l3/variants.ts +13 -0
  37. package/src/e-cna/slides/math-perception/index.ts +1 -0
  38. package/src/e-cna/slides/math-perception/variants.ts +30 -0
  39. package/src/e-cna/slides/other_curriculum/index.ts +1 -0
  40. package/src/e-cna/slides/other_curriculum/variants.ts +14 -0
  41. package/src/e-cna/slides/school_performance_5_12/index.ts +1 -0
  42. package/src/e-cna/slides/school_performance_5_12/variants.ts +23 -0
  43. package/src/e-cna/slides/school_performance_kg_4/index.ts +1 -0
  44. package/src/e-cna/slides/school_performance_kg_4/variants.ts +25 -0
  45. package/src/e-cna/slides/secondary_needs/index.ts +1 -0
  46. package/src/e-cna/slides/secondary_needs/variants.ts +26 -0
  47. package/src/e-cna/slides/signup/index.ts +1 -0
  48. package/src/e-cna/slides/signup/variants.ts +7 -0
  49. package/src/e-cna/slides/signup_refer/index.ts +1 -0
  50. package/src/e-cna/slides/signup_refer/variants.ts +16 -0
  51. package/src/e-cna/slides/slot_pick/index.ts +1 -0
  52. package/src/e-cna/slides/slot_pick/variants.ts +7 -0
  53. package/src/e-cna/utils/index.ts +29 -0
  54. package/src/index.ts +3 -0
  55. package/src/local-storage/index.ts +191 -0
  56. package/.vscode/settings.json +0 -1
@@ -0,0 +1,363 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import dayjs from 'dayjs';
3
+ import relativeTime from 'dayjs/plugin/relativeTime';
4
+
5
+ import {
6
+ shorthandWeekDayArray,
7
+ monthArray,
8
+ TWENTY_FOUR_HOURS_IN_SECONDS,
9
+ HOUR_FORMAT,
10
+ } from '../constants/date-time';
11
+ import { timezones } from '../constants/date-time/e-cna-international-timezones';
12
+
13
+ type Timestamp = number;
14
+
15
+ export interface DateSlots {
16
+ key: number;
17
+ label: string;
18
+ subLabel: string;
19
+ disabled: boolean;
20
+ }
21
+
22
+ export const formatDateTime = (
23
+ dateTime: string | number | Date | dayjs.Dayjs | null | undefined,
24
+ format: string | undefined,
25
+ ) => {
26
+ const momentDate = dayjs(dateTime);
27
+
28
+ return momentDate.format(format);
29
+ };
30
+
31
+ export function getCurrentTimestamp(): number {
32
+ if (!Date.now) {
33
+ Date.now = () => new Date().getTime();
34
+ }
35
+
36
+ return Math.floor(Date.now() / 1000);
37
+ }
38
+
39
+ export function dateTimeByTimezone(timestamp: Timestamp, timezone?: string) {
40
+ let options = {};
41
+
42
+ if (timezone) {
43
+ options = {
44
+ timeZone: timezone,
45
+ };
46
+ }
47
+
48
+ return new Date(timestamp).toLocaleString('en-US', options);
49
+ }
50
+
51
+ export function dateByTimezone(timestamp: number, timezone: string, format: string) {
52
+ const datetime = dateTimeByTimezone(timestamp, timezone);
53
+
54
+ return dayjs(datetime).format(format || 'mm/dd/yyyy');
55
+ }
56
+
57
+ export const dateByTimestamp = (timestamp: Timestamp, format: string) => {
58
+ const datetime = new Date(timestamp).toLocaleString('en-US');
59
+
60
+ return dayjs(datetime).format(format || 'mm/dd/yyyy');
61
+ };
62
+
63
+ export function convertTimeStampToSeconds(timeStamp: Timestamp) {
64
+ const demoTimeStamp = timeStamp;
65
+ const currentTimeStamp = getCurrentTimestamp();
66
+
67
+ if (Number.isNaN(demoTimeStamp) || Number.isNaN(currentTimeStamp)) {
68
+ return timeStamp;
69
+ }
70
+
71
+ const demoTimeStampLength = String(demoTimeStamp).length;
72
+ const currentTimeStampLength = String(currentTimeStamp).length;
73
+
74
+ return demoTimeStampLength > currentTimeStampLength ? timeStamp / 1000 : timeStamp;
75
+ }
76
+
77
+ export function formatTimestamp(datetime: Timestamp, format: string | undefined) {
78
+ const timeStamp = convertTimeStampToSeconds(datetime);
79
+
80
+ return dayjs.unix(timeStamp).format(format);
81
+ }
82
+
83
+ export function getTimezone() {
84
+ return Intl?.DateTimeFormat().resolvedOptions().timeZone;
85
+ }
86
+
87
+ export function timeToX(
88
+ datetime: string | number | Date | dayjs.Dayjs | null | undefined,
89
+ ) {
90
+ dayjs.extend(relativeTime);
91
+
92
+ return dayjs().to(datetime, true);
93
+ }
94
+
95
+ export function getCurrentDatebyTimezone(timezone: string) {
96
+ let options = {};
97
+
98
+ if (timezone) {
99
+ options = {
100
+ timeZone: timezone,
101
+ };
102
+ }
103
+
104
+ return new Date().toLocaleString('en-US', options);
105
+ }
106
+
107
+ export function getTimeDiff(
108
+ date1: string | number | Date | dayjs.Dayjs | null | undefined,
109
+ date2: string | number | Date | dayjs.Dayjs | null | undefined,
110
+ ) {
111
+ const dateTime1 = dayjs(date1);
112
+ const dateTime2 = dayjs(date2);
113
+
114
+ return {
115
+ days: dateTime1.diff(dateTime2, 'days'),
116
+ hour: dateTime1.diff(dateTime2, 'hour'),
117
+ minute: dateTime1.diff(dateTime2, 'minute'),
118
+ seconds: dateTime1.diff(dateTime2, 'seconds'),
119
+ distance: dateTime1.diff(dateTime2),
120
+ };
121
+ }
122
+
123
+ // function roundTime(time: Date) {
124
+ // time.setHours(time.getHours() + Math.round(time.getMinutes() / 60));
125
+ // time.setMinutes(0, 0, 0);
126
+ // }
127
+
128
+ // function getTimeString(increment: number, time: Date, timezone: string) {
129
+ // const value = dateByTimezone(time, timezone, 'hh:mm a');
130
+
131
+ // time.setTime(time.getTime() + increment * 60 * 1000);
132
+
133
+ // return value;
134
+ // }
135
+
136
+ // export function getSlotsTillNextDay(interval: number, timezone: string) {
137
+ // const today = new Date();
138
+ // const curr = new Date();
139
+
140
+ // roundTime(today);
141
+ // roundTime(curr);
142
+
143
+ // const slots = [];
144
+
145
+ // while (getTimeDiff(today, curr).days !== -1) {
146
+ // slots.push({
147
+ // id: curr.getTime(),
148
+ // value: getTimeString(interval, curr, timezone),
149
+ // });
150
+ // }
151
+
152
+ // return slots;
153
+ // }
154
+
155
+ export function getISOTimeString(demoTs: number) {
156
+ return new Date(demoTs * 1000).toISOString().replace(/-|:|\.\d\d\d/g, '');
157
+ }
158
+
159
+ export function getDateAfterDays(days: number) {
160
+ return formatDateTime(dayjs().add(days, 'day'), 'D MMM, YYYY').toUpperCase();
161
+ }
162
+
163
+ // function convertTZ(date: string | number | Date, tzString: any){
164
+ // return new Date(
165
+ // (typeof date === 'string' ? new Date(date) : date).toLocaleString('en-US', {
166
+ // timeZone: tzString,
167
+ // }),
168
+ // );
169
+ // }
170
+
171
+ // export function getUtcTimestamp(timeZone: any, date: string) {
172
+ // const time = convertTZ(date, timeZone);
173
+
174
+ // const parsedDate = Date.parse(time);
175
+
176
+ // return parsedDate / 1000;
177
+ // }
178
+
179
+ export const convertedTimezone = (selectedTimezone: string) => {
180
+ const formattedTimezone = timezones?.filter(
181
+ currentTimezone => currentTimezone?.id === selectedTimezone,
182
+ );
183
+
184
+ if (formattedTimezone?.length) {
185
+ return formattedTimezone[0]?.value;
186
+ }
187
+
188
+ return selectedTimezone?.replaceAll('_', ' ');
189
+ };
190
+
191
+ export const getHourInTwelveHourFormat = (hour: number) => {
192
+ return hour % 12 === 0 ? 12 : hour % 12;
193
+ };
194
+
195
+ export const getMeridiemAccordingToHourAndHourFormat = (
196
+ hour: number,
197
+ hourFormat: number,
198
+ meridiem = '',
199
+ ) => {
200
+ if (hourFormat === HOUR_FORMAT.TWENTY_FOUR_HOUR_FORMAT) {
201
+ return hour / 12 >= 1 ? 'PM' : 'AM';
202
+ }
203
+
204
+ return hour === 12 ? 'PM' : meridiem;
205
+ };
206
+
207
+ export const getTimeSlotDuration = (selectedTime: number, selectedTimezone: any) => {
208
+ const firstHour = getHourInTwelveHourFormat(selectedTime);
209
+ const firstMeridiem = getMeridiemAccordingToHourAndHourFormat(
210
+ selectedTime,
211
+ HOUR_FORMAT.TWENTY_FOUR_HOUR_FORMAT,
212
+ );
213
+
214
+ const secondHour = getHourInTwelveHourFormat(selectedTime + 1);
215
+ const secondMeridiem = getMeridiemAccordingToHourAndHourFormat(
216
+ selectedTime + 1,
217
+ HOUR_FORMAT.TWENTY_FOUR_HOUR_FORMAT,
218
+ );
219
+ const currentTimeZone =
220
+ convertedTimezone(selectedTimezone)?.split('(') || selectedTimezone;
221
+
222
+ return `${firstHour} ${firstMeridiem.toLowerCase()} - ${secondHour} ${secondMeridiem.toLowerCase()} (${currentTimeZone})`;
223
+ };
224
+
225
+ export const convertSecondsToMiliseconds = (seconds: number) => {
226
+ return seconds * 1000;
227
+ };
228
+
229
+ // convert date into Sept 01, Thursday format
230
+ export const convertDate = (selectedDate: number, selectedTimezone: string) => {
231
+ const slotDate = formatTimestamp(selectedDate, 'DD-MM-YYYY');
232
+ const dayOfWeek = dateByTimezone(selectedDate * 1000, selectedTimezone, 'dddd');
233
+ const dateArr = slotDate?.split('-');
234
+ const month = dateArr?.[1];
235
+ const day = dateArr?.[0];
236
+
237
+ return `${monthArray[parseInt(month, 10) - 1]} ${day}, ${dayOfWeek}`;
238
+ };
239
+
240
+ export const getModifiedDateSlots = (dateSlotsData: { label: string }[]) => {
241
+ const startWeekIndex = shorthandWeekDayArray?.indexOf(dateSlotsData?.[0]?.label);
242
+
243
+ // get all days
244
+ let weekDays: { label: string; removeBorder?: boolean }[] = [];
245
+
246
+ // while loop to check start date's day
247
+ // for eg: if first date is wednesday, it will add blank days on monday, tuesday
248
+ while (weekDays.length !== startWeekIndex) {
249
+ weekDays.push({
250
+ label: '',
251
+ removeBorder: false,
252
+ });
253
+ }
254
+ weekDays = [...weekDays, ...dateSlotsData];
255
+
256
+ // while loop to add check end date
257
+ // for eg: if last date end's on friday, it will add blank days on saturday and sunday
258
+ while (weekDays.length % 7 !== 0) {
259
+ weekDays.push({
260
+ label: '',
261
+ removeBorder: false,
262
+ });
263
+ }
264
+ const weekRows = [];
265
+
266
+ // divide weekDays in weeks group
267
+ while (weekDays.length !== 0) {
268
+ const row =
269
+ weekDays?.length >= 7
270
+ ? weekDays?.splice(0, 7)
271
+ : weekDays?.splice(0, weekDays?.length);
272
+
273
+ weekRows.push(row);
274
+ }
275
+
276
+ return weekRows;
277
+ };
278
+
279
+ // Array of 7 days
280
+ export const getDates = (timezone: string) => {
281
+ const currentDate = Date.parse(getCurrentDatebyTimezone(timezone)) / 1000;
282
+ const dates = [];
283
+
284
+ // getting dates by adding 86400 seconds(24 hours)
285
+ for (let i = 0; i < 7; i++) {
286
+ dates.push({
287
+ futureDate: currentDate + TWENTY_FOUR_HOURS_IN_SECONDS * i,
288
+ disabled: !(i > 1),
289
+ });
290
+ }
291
+
292
+ return dates;
293
+ };
294
+
295
+ export function formatDateFromTimestamp(
296
+ timestamp: string | number | Date,
297
+ format: string,
298
+ ) {
299
+ const datetime = new Date(timestamp).toLocaleString('en-US');
300
+
301
+ return dayjs(datetime).format(format || 'mm/dd/yyyy');
302
+ }
303
+
304
+ export function getAvailableDateSlots(currentTimezone: any) {
305
+ const availableDateSlots: DateSlots[] = [];
306
+
307
+ getDates(currentTimezone).map(item => {
308
+ const { futureDate, disabled } = item;
309
+
310
+ availableDateSlots.push({
311
+ key: futureDate,
312
+ label: formatDateFromTimestamp(futureDate * 1000, 'dd'),
313
+ subLabel: formatDateFromTimestamp(futureDate * 1000, 'DD'),
314
+ disabled,
315
+ });
316
+
317
+ return null;
318
+ });
319
+
320
+ return availableDateSlots;
321
+ }
322
+
323
+ export const toTimestamp = (strDate: string) => {
324
+ return Date.parse(strDate) / 1000;
325
+ };
326
+
327
+ export const getDateSlots = (timezone: any) => {
328
+ return getDates(timezone).map(item => {
329
+ const { futureDate, disabled } = item;
330
+
331
+ return {
332
+ key: futureDate,
333
+ label: dateByTimestamp(futureDate * 1000, 'dd'),
334
+ subLabel: dateByTimestamp(futureDate * 1000, 'DD'),
335
+ disabled,
336
+ };
337
+ });
338
+ };
339
+
340
+ // export const getUtcUnixTimestamp = (date: number, time: any, timezone: any) => {
341
+ // const formatDate = formatTimestamp(date, 'MM/DD/YYYY');
342
+ // const convertedDatTime = dateTimeByTimezone(
343
+ // toTimestamp(`${formatDate} ${time}`) * 1000
344
+ // );
345
+
346
+ // return getUtcTimestamp(timezone, convertedDatTime);
347
+ // };
348
+
349
+ export const getTimeSlotDurationForSlotPage = (selectedTime: string) => {
350
+ const timeArr = selectedTime.split(':');
351
+ const firstHour = timeArr?.[0];
352
+ const meridiem = timeArr?.[1]?.split(' ')?.[1];
353
+
354
+ const secondHourInTwelveHourFormat = parseInt(firstHour, 10) + 1;
355
+ const secondHour = getHourInTwelveHourFormat(secondHourInTwelveHourFormat);
356
+ const secondMeridiem = getMeridiemAccordingToHourAndHourFormat(
357
+ secondHourInTwelveHourFormat,
358
+ HOUR_FORMAT.TWELVE_HOUR_FORMAT,
359
+ meridiem,
360
+ );
361
+
362
+ return `${firstHour} ${meridiem.toLowerCase()} - ${secondHour} ${secondMeridiem.toLowerCase()}`;
363
+ };
@@ -0,0 +1,6 @@
1
+ import { DEFAULT_FLOW } from './variants';
2
+
3
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
4
+ export const getFlow = (flow: string) => {
5
+ return DEFAULT_FLOW;
6
+ };
@@ -0,0 +1 @@
1
+ export * from './aggregator';
@@ -0,0 +1,40 @@
1
+ import {
2
+ intro,
3
+ grade,
4
+ key_need_l1,
5
+ key_need_l2,
6
+ math_perception,
7
+ school_performance_5_12,
8
+ school_performance_kg_4,
9
+ child_hobbies,
10
+ child_personality,
11
+ key_need_l3,
12
+ other_curriculum,
13
+ secondary_needs,
14
+ signup_refer,
15
+ signup,
16
+ slot_pick,
17
+ } from '../../slides';
18
+
19
+ export const DEFAULT_FLOW = {
20
+ intro: intro.DEFAULT,
21
+ grade: grade.DEFAULT,
22
+ math_perception: math_perception.DEFAULT,
23
+ school_performance_5_12: school_performance_5_12.DEFAULT,
24
+ school_performance_kg_4: school_performance_kg_4.DEFAULT,
25
+ key_need_l1: key_need_l1.DEFAULT,
26
+ strong_math_foundation: key_need_l2.STRONG_MATH_FOUNDATION,
27
+ mental_math: key_need_l2.MENTAL_MATH,
28
+ learning_gaps: key_need_l2.LEARNING_GAPS,
29
+ more_practice: key_need_l2.MORE_PRACTICE,
30
+ develop_interest: key_need_l2.DEVELOP_INTEREST,
31
+ advanced_and_competitive_maths: key_need_l2.ADVANCE_AND_COMPETITIVE_MATHS,
32
+ key_need_l3: key_need_l3.DEFAULT,
33
+ secondary_needs: secondary_needs.DEFAULT,
34
+ child_personality: child_personality.DEFAULT,
35
+ child_hobbies: child_hobbies.DEFAULT,
36
+ slot_pick: slot_pick.DEFAULT,
37
+ parent_student_details: signup.DEFAULT,
38
+ other_curriculum: other_curriculum.DEFAULT,
39
+ signup_refer: signup_refer.DEFAULT,
40
+ };
@@ -0,0 +1 @@
1
+ export * from './default';
@@ -0,0 +1,264 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import { ASSESSMENT_ID, CUE_COUNTRY_CODE_KEY, SLIDE_TYPES } from '../constants';
3
+ import { getCookie } from '../cookie';
4
+ import { getTimezone, dateByTimezone, getCurrentTimestamp } from '../date-time-helper';
5
+
6
+ // interface Timezone {
7
+ // id: string;
8
+ // value: string;
9
+ // meta: string;
10
+ // }
11
+
12
+ const showCallModalURL: string[] = [
13
+ SLIDE_TYPES.INTRO,
14
+ SLIDE_TYPES.QUESTION,
15
+ SLIDE_TYPES.SLOT_PICK,
16
+ SLIDE_TYPES.PARENT_STUDENT_DETAILS,
17
+ ];
18
+ const ignoreCallModalURL: string[] = ['otp_enabled'];
19
+ const ECNA = '#/e-cna/';
20
+
21
+ export const timeSlots = {
22
+ now: 'Now',
23
+ anytime: 'Anytime',
24
+ today: 'Today',
25
+ tomorrow: 'Tomorrow',
26
+ };
27
+
28
+ export const ecnaSlideTypeName = {
29
+ CLASS_CONFIRMED: SLIDE_TYPES.CLASS_CONFIRMED,
30
+ };
31
+
32
+ export const getSlideDetails = (path: string) => {
33
+ const hash = path?.split('#')[1] || '';
34
+ const href = hash?.split('/') || [];
35
+
36
+ const slideType = href?.[2];
37
+ let slideId: string | number = href?.[3];
38
+
39
+ if (slideType === ecnaSlideTypeName.CLASS_CONFIRMED) {
40
+ slideId = 16;
41
+ }
42
+
43
+ if (slideId === 'curriculum') {
44
+ slideId = 17;
45
+ }
46
+
47
+ return {
48
+ slideType,
49
+ slideId,
50
+ };
51
+ };
52
+
53
+ export function handleModalClose(
54
+ path: string,
55
+ // actions: any
56
+ ) {
57
+ // const { slideType, slideId } = getSlideDetails(path);
58
+
59
+ // parentAnalytics.ecnaModalClosed(
60
+ // slideType === SLIDE_TYPES.QUESTION ? questionsData[slideId]?.questionID : slideType,
61
+ // );
62
+
63
+ if (!path) {
64
+ return 'close';
65
+ }
66
+
67
+ const filteredData = showCallModalURL.filter(key => path.includes(`${ECNA}${key}`));
68
+ const noCallfilteredData = ignoreCallModalURL.filter(key => path.includes(key));
69
+
70
+ if (filteredData.length && !noCallfilteredData.length) {
71
+ setTimeout(() => {
72
+ // const isMobileView = (window && window.innerWidth <= 767) || false;
73
+ // Router.pushRoute(`${ECNA}exit-parent/`);
74
+ // openEcnaModal({ actions, isMobileView });
75
+ }, 500);
76
+ } else {
77
+ // Router.pushRoute('#');
78
+ }
79
+
80
+ return 'close';
81
+ }
82
+
83
+ // export function openEcnaModal({ actions, isMobileView, type, id }): void {
84
+ // actions.openModal(
85
+ // 'e-cna-form',
86
+ // {
87
+ // size: 'custom',
88
+ // width: '624px',
89
+ // height: isMobileView && window ? 'auto' : '548px',
90
+ // style: {
91
+ // backgroundColor: `${COLORS.WILD_SAND}`,
92
+ // padding: '0px',
93
+ // },
94
+ // outSideCloseButton: true,
95
+ // blocking: !isMobileView,
96
+ // handleModalClose: (path, modalActions) => handleModalClose(path, modalActions),
97
+ // enableTransform: !isMobileView,
98
+ // },
99
+ // {
100
+ // type,
101
+ // id,
102
+ // },
103
+ // );
104
+ // }
105
+
106
+ // export const handleOpenEcnaModal = ({ actions, isMobileView, type, id }) => {
107
+ // openEcnaModal({ actions, isMobileView, type, id });
108
+ // };
109
+
110
+ const getTime = (baseTime: number, requiredTime: number) => {
111
+ return baseTime + requiredTime * 60 * 60;
112
+ };
113
+
114
+ const getTimeFormat = (reqtime: number, format = 'ha') => {
115
+ const timezone = getTimezone();
116
+
117
+ return dateByTimezone(reqtime, timezone, format);
118
+ };
119
+
120
+ const getTitle = (noOfDaysFromToday: number, requiredDay: number) => {
121
+ if (noOfDaysFromToday === 0) {
122
+ return timeSlots.today;
123
+ }
124
+
125
+ if (noOfDaysFromToday === 1) {
126
+ return timeSlots.tomorrow;
127
+ }
128
+
129
+ const timezone = getTimezone();
130
+
131
+ return dateByTimezone(requiredDay, timezone, 'DD/MM/YYYY');
132
+ };
133
+
134
+ export const getSlots = (noOfDaysFromToday = 0, slotDetails = []) => {
135
+ const dateCon = new Date();
136
+ const requiredDay = dateCon.setDate(dateCon.getDate() + noOfDaysFromToday);
137
+
138
+ dateCon.setHours(0, 0, 0, 0); // making time 12am
139
+ const baseTime = dateCon.getTime() / 1000;
140
+ const currentTime = getCurrentTimestamp();
141
+
142
+ const tabSlots = slotDetails?.map(({ from, to, custom }) => {
143
+ // 'Now' slot condition. Keeping it for future usage
144
+ // if (custom === timeSlots.now) {
145
+ // return ({
146
+ // key: custom,
147
+ // label: custom,
148
+ // slot: { from: currentTime }
149
+ // })
150
+ // }
151
+
152
+ const anyTimeStamp = getTime(baseTime, 20); // 8pm timestamp. choosen randomly
153
+
154
+ if (custom === timeSlots.anytime) {
155
+ return {
156
+ key: anyTimeStamp,
157
+ label: custom,
158
+ slot: { from: '', to: anyTimeStamp },
159
+ };
160
+ }
161
+
162
+ const fromTime = getTime(baseTime, from);
163
+ const toTime = getTime(baseTime, to);
164
+ const fromTimeFormat = getTimeFormat(fromTime * 1000);
165
+ const toTimeFormat = getTimeFormat(toTime * 1000);
166
+ const isDisabled = currentTime - toTime > 0;
167
+
168
+ return {
169
+ key: `${fromTime}${toTime}`,
170
+ label: `${fromTimeFormat} - ${toTimeFormat}`,
171
+ disabled: isDisabled,
172
+ slot: { from: fromTime, to: toTime },
173
+ };
174
+ });
175
+
176
+ const data = { title: getTitle(noOfDaysFromToday, requiredDay), slots: tabSlots };
177
+
178
+ return data;
179
+ };
180
+
181
+ export const getOrigin = () => {
182
+ const { origin = '' } =
183
+ typeof window !== 'undefined' && window.location ? window.location : {};
184
+
185
+ return origin;
186
+ };
187
+
188
+ export const getQueryField = (asPath: string, field: string) => {
189
+ let searchParams: any = asPath?.split('?') || [];
190
+
191
+ searchParams = searchParams.length > 2 ? searchParams[2] : searchParams[1];
192
+ const params = new URLSearchParams(searchParams);
193
+
194
+ return params.get(field) || '';
195
+ };
196
+
197
+ // export const FadeIn = keyframes`
198
+ // from {
199
+ // opacity: 0;
200
+ // transform: translateX(480px);
201
+
202
+ // }
203
+ // to {
204
+ // opacity: 1;
205
+ // transform: translateX(0);
206
+ // }
207
+ // `;
208
+
209
+ export const getCounsellorSpelling = () => {
210
+ const cueCountryCode = getCookie('cue_country_code');
211
+
212
+ return cueCountryCode === 'US' ? 'Counselor' : 'Counsellor';
213
+ };
214
+
215
+ // export const uniqueTimeZones = [
216
+ // ...new Map(timezones.map(item => [item.value, item])).values(),
217
+ // ];
218
+
219
+ // export let countrySpecificTimezones = uniqueTimeZones.filter(uniqueTimezone => {
220
+ // const countryCode = getCookie('cue_country_code');
221
+
222
+ // if (countryCode) {
223
+ // return countryTimezones?.countries?.[getCookie('cue_country_code')]?.zones?.find(
224
+ // countryTimezone => {
225
+ // return countryTimezone === uniqueTimezone?.id;
226
+ // },
227
+ // );
228
+ // }
229
+
230
+ // return uniqueTimezone;
231
+ // });
232
+
233
+ export const sendFieldEventToWebengage = (label: string | number, value: any) => {
234
+ if (getCookie(ASSESSMENT_ID)) {
235
+ const field: { [key: string]: [value: string] } = {};
236
+
237
+ field[label] = value;
238
+ // parentAnalytics.signupFieldFilled(field);
239
+ }
240
+ };
241
+
242
+ export const isOtpRequired = (cueCountryCode: string) => {
243
+ const noOtpCountrycodes = ['AU', 'NZ', 'SG'];
244
+
245
+ return !(noOtpCountrycodes.findIndex(key => key === cueCountryCode) > -1);
246
+ };
247
+
248
+ export const getUrlWithoutHash = (asPath: string) => {
249
+ return asPath?.includes('#') ? asPath.split('#')[0] : asPath;
250
+ };
251
+
252
+ export const showLaptopQuestion = () => {
253
+ const cueCountryCode = getCookie(CUE_COUNTRY_CODE_KEY);
254
+
255
+ return cueCountryCode === 'IN';
256
+ };
257
+
258
+ export const nonROWCountries: string[] = ['IN', 'US', 'CA'];
259
+
260
+ export const isROWCountry = (countryCode: string) => {
261
+ return !nonROWCountries.includes(countryCode);
262
+ };
263
+
264
+ export * from './flow';
@@ -0,0 +1 @@
1
+ export * from './variants';
@@ -0,0 +1,13 @@
1
+ export const child_hobbies = {
2
+ DEFAULT: {
3
+ id: 15,
4
+ questionID: 'child_hobbies',
5
+ type: 'freeFlowingText',
6
+ question: 'What do they enjoy doing outside of school?',
7
+ description:
8
+ 'Tell us what your child has fun doing and has shown strong interests in.',
9
+ questionUUID: 'ea6a29f3-c6b6-4932-b606-e828070fd6fe',
10
+ placeholderText: 'Loves reading fiction novels, Harry Potter is the favourite',
11
+ nextSlide: 'slot_pick',
12
+ },
13
+ };
@@ -0,0 +1 @@
1
+ export * from './variants';