-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalendar-export-modal.tsx
More file actions
222 lines (210 loc) · 7.29 KB
/
Copy pathcalendar-export-modal.tsx
File metadata and controls
222 lines (210 loc) · 7.29 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
"use client";
import {
Dialog,
DialogPanel,
DialogTitle,
Transition,
TransitionChild,
} from "@headlessui/react";
import { Fragment, useRef, useState } from "react";
interface ModalProps {
modalState: boolean;
setModalState: (state: boolean) => void;
title?: string;
url: string;
}
export default function CalendarExportModal({
modalState,
setModalState,
title = "Export Calendar",
url,
}: ModalProps) {
const [isCopied, setIsCopied] = useState(false);
const [openSections, setOpenSections] = useState<Record<string, boolean>>({});
const sectionRefs = {
how: useRef<HTMLDivElement>(null),
google: useRef<HTMLDivElement>(null),
apple: useRef<HTMLDivElement>(null),
outlook: useRef<HTMLDivElement>(null),
};
function copyToClipboard() {
navigator.clipboard.writeText(url).then(() => {
setIsCopied(true);
setTimeout(() => setIsCopied(false), 1200);
});
}
const toggleSection = (key: string) => {
setOpenSections((prev) => ({ ...prev, [key]: !prev[key] }));
};
const sections = [
{
key: "how",
title: "How does it work?",
content: (
<div className="space-y-2 text-justify text-sm">
<p>
The URL above allows you to{" "}
<span className="font-medium">subscribe</span> to your shifts.
</p>
<p>You will see your shifts in your calendar app.</p>
<div className="bg-success/30 flex items-center gap-2 rounded-lg p-3 text-sm text-green-700">
<span className="material-symbols-outlined text-base">
check_circle
</span>
If you change shifts, you won't need to re-export and
re-subscribe.
</div>
</div>
),
},
{
key: "google",
title: "Google Calendar",
content: (
<ol className="ml-6 list-decimal space-y-1 text-sm">
<li>
Open{" "}
<a href="https://calendar.google.com" className="text-primary-400">
Google Calendar
</a>
.
</li>
<li>On the left, click Add → From URL.</li>
<li>Enter the above calendar’s address.</li>
<li>Click Add Calendar.</li>
</ol>
),
},
{
key: "apple",
title: "Apple Calendar",
content: (
<ol className="ml-6 list-decimal space-y-1 text-sm">
<li>Open Calendar on your iPhone or Mac.</li>
<li>Click Add Calendar → Add Subscription Calendar.</li>
<li>Enter the above calendar’s address and subscribe.</li>
</ol>
),
},
{
key: "outlook",
title: "Outlook Calendar",
content: (
<ol className="ml-6 list-decimal space-y-1 text-sm">
<li>Sign in to Outlook.com.</li>
<li>Select Add Calendar → Subscribe from web.</li>
<li>Enter the above calendar’s address.</li>
</ol>
),
},
];
return (
<Transition appear show={modalState} as={Fragment}>
<Dialog
as="div"
className="relative z-50"
onClose={() => setModalState(false)}
>
<TransitionChild
as={Fragment}
enter="ease-out duration-300"
enterFrom="opacity-0"
enterTo="opacity-100"
leave="ease-in duration-200"
leaveFrom="opacity-100"
leaveTo="opacity-0"
>
<div className="bg-dark/5 fixed inset-0 backdrop-blur-sm" />
</TransitionChild>
<div className="fixed inset-0 flex items-center justify-center p-4">
<TransitionChild
as={Fragment}
enter="ease-out duration-300"
enterFrom="opacity-0 scale-95"
enterTo="opacity-100 scale-100"
leave="ease-in duration-200"
leaveFrom="opacity-100 scale-100"
leaveTo="opacity-0 scale-95"
>
<DialogPanel className="bg-muted/65 relative w-full max-w-lg flex-1 space-y-4 rounded-2xl border border-black/10 p-6 shadow-xl focus:outline-0">
{title && (
<div className="flex items-center justify-between">
<DialogTitle className="text-dark text-2xl font-semibold">
{title}
</DialogTitle>
<button
className="material-symbols-outlined text-dark/50 cursor-pointer text-2xl transition-opacity ease-in-out hover:opacity-70"
onClick={() => setModalState(false)}
>
close
</button>
</div>
)}
<div
onClick={copyToClipboard}
className={`text-dark bg-light/70 border-dark/10 w-full cursor-pointer rounded-lg border px-3 py-2 transition-colors duration-200 ${
isCopied
? "bg-green-100 hover:bg-green-200"
: "hover:bg-primary-100"
}`}
>
<div className="no-scrollbar overflow-x-auto text-sm whitespace-nowrap">
{url}
</div>
<div
className={`mt-1 text-xs ${isCopied ? "text-green-700" : "text-dark/50"}`}
>
{isCopied ? "Copied!" : "Click to copy"}
</div>
</div>
<div className="divide-dark/10 divide-y">
{sections.map((section) => (
<div key={section.key} className="py-2">
<button
onClick={() => toggleSection(section.key)}
className="text-dark flex w-full items-center justify-between text-left text-base font-medium"
>
{section.title}
<span className="material-symbols-outlined text-dark/60">
{openSections[section.key]
? "expand_less"
: "expand_more"}
</span>
</button>
<div
ref={sectionRefs[section.key as keyof typeof sectionRefs]}
className="overflow-hidden transition-[max-height] duration-300"
style={{
maxHeight: openSections[section.key]
? `${
sectionRefs[
section.key as keyof typeof sectionRefs
].current?.scrollHeight || 0
}px`
: 0,
}}
>
<div className="mt-2">{section.content}</div>
</div>
</div>
))}
</div>
<div className="text-dark/80 mt-4 flex items-center gap-2 text-sm">
<span className="material-symbols-outlined text-base">
lightbulb
</span>
<span>
You can also{" "}
<a href={url} className="text-primary-400 font-medium">
download as .ics file
</a>
.
</span>
</div>
</DialogPanel>
</TransitionChild>
</div>
</Dialog>
</Transition>
);
}