-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathPopup.tsx
More file actions
557 lines (515 loc) · 16.5 KB
/
Popup.tsx
File metadata and controls
557 lines (515 loc) · 16.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
"use client";
import Image from "next/image";
import React, { useState, useEffect } from "react";
import { BasicToggleButton, GoogleLoginButton, ZButton } from "./Buttons";
import CompoundTable from "./CompoundTable";
import LoadingPopup from "./LoadingPopup";
type dataProps = {
code: string;
slot: string;
name: string;
};
type PopupProps = {
type:
| "login"
| "rem_course"
| "rem_allcourse"
| "share_tt"
| "save_tt"
| "delete_tt"
| "view_tt"
| "logout"
| "rename_tt";
dataTitle?: string;
dataBody?: string;
dataTT?: dataProps[];
closeLink: () => void;
action?: () => void;
shareEnabledDefault?: boolean;
shareSwitchAction?: (state: "on" | "off") => void;
onInputChange?: (val: string) => void;
};
const colorMap = {
red: ["#FFD3D3", "#FF8C8C"],
yellow: ["#FFF8D1", "#FFEA79"],
green: ["#E5FFDE", "#ABDE9F"],
blue: ["#E2F2F9", "#8BD5FF"],
purple: ["#E4E9FC", "#94ACFF"],
};
const typeColorMap = {
login: "yellow",
rem_course: "red",
rem_allcourse: "red",
share_tt: "blue",
save_tt: "green",
delete_tt: "red",
view_tt: "blue",
logout: "red",
rename_tt: "purple",
};
const typeTitleMap = {
login: "Sign In",
rem_course: "Remove Course",
rem_allcourse: "Remove All",
share_tt: "Share Timetable",
save_tt: "Save Timetable",
delete_tt: "Delete Timetable",
view_tt: "",
logout: "Log Out",
rename_tt: "Rename Timetable",
};
const typeTextMap = {
login: "Please log-in to save and share your time-tables.",
rem_course: "Are you sure you want to remove this course?",
rem_allcourse: "Are you sure you want to remove all courses?",
share_tt: "Share your timetable with anyone.",
save_tt: "Save this timetable in your collection.",
delete_tt: "Are you sure you want to delete this timetable?",
view_tt: "",
logout: "Are you sure you want to log out?",
rename_tt: "Enter a new name for your timetable.",
};
function copy(text: string) {
if (typeof navigator !== "undefined" && navigator.clipboard) {
navigator.clipboard.writeText(String(text));
}
}
export default function Popup({
type,
dataTitle,
dataBody = "",
dataTT,
closeLink,
action,
shareEnabledDefault,
shareSwitchAction,
onInputChange,
isLoading = false,
}: PopupProps & { isLoading?: boolean }) {
const theme = colorMap[typeColorMap[type] as keyof typeof colorMap] || [
"#E4E9FC",
"#94ACFF",
];
const title = typeTitleMap[type] || dataTitle || "";
const text = typeTextMap[type] || "";
const shareEnabled =
shareEnabledDefault !== undefined ? shareEnabledDefault : true;
const [shareState] = useState<"on" | "off">(shareEnabled ? "on" : "off");
const [isInvalid, setIsInvalid] = useState(false);
useEffect(() => {
document.body.style.overflow = "hidden";
return () => {
document.body.style.overflow = "";
};
}, []);
return (
<div className="fixed inset-0 flex items-center justify-center bg-[#425D5F]/75 backdrop-blur-xs z-50">
{type === "share_tt" && isLoading && <LoadingPopup isLoading={true} />}
<div
style={{ backgroundColor: theme[0] }}
className={`
inline-flex flex-col
rounded-3xl
mb-8 mt-0
outline-4 outline-black
shadow-[10px_10px_0_0_black]
box-border
items-stretch
max-w-[80vw] max-h-[80vh]
min-w-120 min-h-48
`}
>
<div
style={{ backgroundColor: theme[1] }}
className={`
rounded-t-3xl
flex items-center
text-lg
font-semibold
outline-4 outline-black
justify-between
relative
pl-2
h-12
`}
>
<div className="flex-1 text-left flex items-center justify-start pl-4">
<div className="flex gap-2">
{[...Array(3)].map((_, i) => (
<div
key={i}
className="w-4 h-4 rounded-full bg-black opacity-50"
/>
))}
</div>
</div>
<div className="absolute left-1/2 -translate-x-1/2 text-center flex items-center justify-center font-poppins font-bold text-2xl">
{title}
</div>
{!(
type == "delete_tt" ||
type == "rem_course" ||
type == "logout" ||
type == "rem_allcourse"
) && (
<div className="flex-1 text-right flex items-center justify-end">
<div
className={`
w-12 h-12
bg-[#FF9A9A]
rounded-tr-3xl
flex items-center
justify-center
cursor-pointer
outline-4 outline-black
pt-1 pr-1
`}
onClick={() => closeLink()}
>
<Image
src="/icons/cross.svg"
alt="close"
width={32}
height={32}
draggable={false}
unselectable="on"
priority
/>
</div>
</div>
)}
</div>
<div className="flex flex-col items-center justify-center text-lg font-poppins font-regular p-8">
{type == "login" && (
<div className="flex flex-col items-center justify-center relative">
<div className="absolute -top-0 -left-12 -rotate-[5deg] z-[1]">
<Image
src="/art/art_rice.svg"
alt="artwork1"
width={32}
height={32}
unselectable="on"
draggable={false}
priority
/>
</div>
<div className="absolute top-1 -right-10 rotate-[-0deg] z-[1]">
<Image
src="/art/art_boom.svg"
alt="artwork2"
width={36}
height={36}
unselectable="on"
draggable={false}
priority
/>
</div>
<div className="absolute -bottom-1 -left-10 -rotate-[5deg] z-[1]">
<Image
src="/art/art_arrow.svg"
alt="artwork3"
width={72}
height={72}
unselectable="on"
draggable={false}
priority
/>
</div>
<div className="absolute -bottom-4 -right-7 rotate-[5deg] z-[1]">
<Image
src="/art/art_loop.svg"
alt="artwork4"
width={60}
height={60}
unselectable="on"
draggable={false}
priority
/>
</div>
<div className="break-words max-w-xs w-full text-center mt-4 mb-8 z-10">
{text}
</div>
<GoogleLoginButton onClick={action} />
<div className="mt-8" />
</div>
)}
{type == "share_tt" && (
<div className="flex flex-col items-center justify-center">
<div className="break-words w-full text-center mt-2 mb-4">
{text}
</div>
{shareState === "on" && (
<div className="flex flex-row items-center justify-center gap-8 mt-2 mb-4">
<div className="border-3 border-black pt-2 pb-2 px-4 rounded-xl shadow-[4px_4px_0_0_black] bg-white text-[#606060] font-semibold">
{dataBody}
</div>
<ZButton
type="regular"
text="Copy"
color="blue"
forceColor={theme[1]}
onClick={() => copy(dataBody || "")}
/>
</div>
)}
</div>
)}
{type == "rem_course" && (
<div>
<div className="break-words max-w-lg w-full text-center mt-2 mb-8">
{text}
<br />
{dataBody && (
<span className="font-semibold">"{dataBody}"</span>
)}
</div>
<div className="flex flex-row items-center justify-center gap-4 mb-4">
<ZButton
type="regular"
text="Cancel"
color="yellow"
forceColor="#FFEA79"
onClick={closeLink}
/>
<ZButton
type="regular"
text="Remove"
color="red"
forceColor={theme[1]}
onClick={action}
/>
</div>
</div>
)}
{type == "rem_allcourse" && (
<div>
<div className="break-words max-w-lg w-full text-center mt-2 mb-8">
{text}
<br />
{dataBody && (
<span className="font-semibold">"{dataBody}"</span>
)}
</div>
<div className="flex flex-row items-center justify-center gap-4 mb-4">
<ZButton
type="regular"
text="Cancel"
color="yellow"
forceColor="#FFEA79"
onClick={closeLink}
/>
<ZButton
type="regular"
text="Remove"
color="red"
forceColor={theme[1]}
onClick={action}
/>
</div>
</div>
)}
{type == "delete_tt" && (
<div>
<div className="break-words max-w-lg w-full text-center mt-2 mb-8">
{text}
<br />
{dataBody && (
<span className="font-semibold">"{dataBody}"</span>
)}
</div>
<div className="flex flex-row items-center justify-center gap-4 mb-4">
<ZButton
type="regular"
text="Cancel"
color="yellow"
forceColor="#FFEA79"
onClick={closeLink}
/>
<ZButton
type="regular"
text="Delete"
color="red"
forceColor={theme[1]}
onClick={action}
/>
</div>
</div>
)}
{type == "save_tt" && (
<div>
<div className="break-words max-w-lg w-full text-center mt-2 mb-8">
{text}
</div>
<div className="flex flex-row items-center justify-center gap-8 mt-2 mb-4">
<div className="border-3 border-black pt-2 pb-2 px-4 rounded-xl shadow-[4px_4px_0_0_black] bg-white text-black font-semibold">
<input
type="text"
className={`bg-transparent outline-none w-full text-center font-semibold border-2 rounded-lg py-1 px-3 ${
isInvalid ? "border-red-500" : "border-white"
}`}
placeholder="Enter timetable name"
value={dataBody}
onChange={(e) => {
const inputValue = e.target.value;
const normalized = inputValue.toLowerCase().replace(/\s+/g, "");
const forbiddenWords = [
"vishvanathan",
"vishvnathan",
"vishwanathan",
"viswanathan",
"vishva",
"viswa",
"vit",
"vellore institute of technology",
"vitstudent",
"vit.ac.in",
"vit vellore",
"vit chennai",
"vit bhopal",
"vit ap",
"vit university",
"vtop",
];
const containsForbidden = forbiddenWords.some((word) =>
normalized.includes(word.replace(/\s+/g, ""))
);
setIsInvalid(containsForbidden);
if (!containsForbidden) {
onInputChange?.(inputValue);
}
}}
/>
</div>
<ZButton
type="regular"
text="Save"
color="green"
forceColor={theme[1]}
onClick={action}
/>
</div>
{isInvalid && (
<div className="text-red-500 text-sm mt-1 text-center">
This name contains restricted words.
</div>
)}
</div>
)}
{type == "rename_tt" && (
<div>
<div className="break-words max-w-lg w-full text-center mt-2 mb-8">
{text}
</div>
<div className="flex flex-row items-center justify-center gap-8 mt-2 mb-4">
<div className="border-3 border-black pt-2 pb-2 px-4 rounded-xl shadow-[4px_4px_0_0_black] bg-white text-black font-semibold">
<input
type="text"
className={`bg-transparent outline-none w-full text-center font-semibold border-2 rounded-lg py-1 px-3 ${
isInvalid ? "border-red-500" : "border-white"
}`}
placeholder="Enter timetable name"
value={dataBody}
onChange={(e) => {
const inputValue = e.target.value;
const normalized = inputValue.toLowerCase().replace(/\s+/g, "");
const forbiddenWords = [
"vishvanathan",
"vishvnathan",
"vishwanathan",
"viswanathan",
"vishva",
"viswa",
"vit",
"vellore institute of technology",
"vitstudent",
"vit.ac.in",
"vit vellore",
"vit chennai",
"vit bhopal",
"vit ap",
"vit university",
"vtop",
];
const containsForbidden = forbiddenWords.some((word) =>
normalized.includes(word.replace(/\s+/g, ""))
);
setIsInvalid(containsForbidden);
if (!containsForbidden) {
onInputChange?.(inputValue);
}
}}
autoFocus
/>
</div>
<ZButton
type="regular"
text="Save"
color="green"
forceColor={theme[1]}
onClick={action}
/>
</div>
{isInvalid && (
<div className="text-red-500 text-sm mt-1 text-center">
This name contains restricted words.
</div>
)}
</div>
)}
{type == "view_tt" && (
<div className="flex flex-col w-full max-h-[90vh] overflow-hidden">
<div className="overflow-auto w-full max-h-[calc(70vh-80px)]">
<div className="min-w-[768px] text-center p-4">
<CompoundTable data={dataTT || []} />
</div>
</div>
<div className="flex flex-row flex-wrap items-center justify-center gap-16 px-4 py-3">
<div className="flex flex-row items-center gap-3">
<ZButton
type="regular"
text="Copy Link"
color="green"
image="/icons/send.svg"
forceColor="#C1FF83"
onClick={action}
/>
</div>
<div className="flex flex-row items-center gap-4">
<span className="font-semibold text-lg">Public Sharing</span>
<BasicToggleButton
key={shareEnabledDefault ? "on" : "off"}
defaultState={shareEnabledDefault ? "on" : "off"}
onToggle={shareSwitchAction ?? (() => {})}
/>
</div>
</div>
</div>
)}
{type === "logout" && (
<div>
<div className="break-words max-w-lg w-full text-center mt-2 mb-8">
{text}
</div>
<div className="flex flex-row items-center justify-center gap-4 mb-4">
<ZButton
type="regular"
text="Cancel"
color="yellow"
forceColor="#FFEA79"
onClick={closeLink}
/>
<ZButton
type="regular"
text="Logout"
color="red"
forceColor={theme[1]}
onClick={action}
/>
</div>
</div>
)}
</div>
</div>
</div>
);
}