@getmicdrop/svelte-components 5.3.13 → 5.3.14
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.
- package/dist/constants/formOptions.d.ts +9 -4
- package/dist/constants/formOptions.d.ts.map +1 -1
- package/dist/constants/formOptions.js +48 -26
- package/dist/index.d.ts +0 -10
- package/dist/index.js +5 -19
- package/dist/stores/auth.js +36 -123
- package/dist/stores/auth.spec.js +139 -447
- package/dist/stores/createFormStore.d.ts +74 -0
- package/dist/stores/createFormStore.d.ts.map +1 -0
- package/dist/stores/createFormStore.js +386 -0
- package/dist/stores/createFormStore.spec.d.ts +2 -0
- package/dist/stores/createFormStore.spec.d.ts.map +1 -0
- package/dist/stores/createFormStore.spec.js +540 -0
- package/dist/telemetry.d.ts +21 -2
- package/dist/telemetry.d.ts.map +1 -1
- package/dist/telemetry.js +403 -358
- package/dist/utils/apiConfig.js +120 -50
- package/dist/utils/utils/utils.js +3 -323
- package/dist/utils/utils.js +644 -346
- package/package.json +16 -1
package/dist/utils/utils.js
CHANGED
|
@@ -1,387 +1,685 @@
|
|
|
1
|
-
import { twMerge } from "tailwind-merge";
|
|
2
|
-
import clsx from "clsx";
|
|
3
|
-
import EventIcon from "../assets/svg/role/event.svg";
|
|
4
|
-
import BookingIcon from "../assets/svg/role/booking.svg";
|
|
5
|
-
import EmailIcon from "../assets/svg/role/emails.svg";
|
|
6
|
-
import VenueIcon from "../assets/svg/role/venue.svg";
|
|
7
|
-
import PayoutIcon from "../assets/svg/role/payout.svg";
|
|
8
|
-
import MarketingIcon from "../assets/svg/role/marketing.svg";
|
|
9
|
-
import OrdersIcon from "../assets/svg/role/orders.svg";
|
|
10
|
-
import OrganisationIcon from "../assets/svg/role/organisation.svg";
|
|
11
|
-
import ReportingIcon from "../assets/svg/role/reporting.svg";
|
|
12
|
-
import microphonePlaceholder from "../assets/images/microphone.png";
|
|
13
|
-
|
|
14
|
-
export function classNames(...classes) {
|
|
15
|
-
return classes.filter(Boolean).join(" ");
|
|
16
|
-
}
|
|
1
|
+
import { twMerge } from "tailwind-merge";
|
|
2
|
+
import clsx from "clsx";
|
|
3
|
+
import EventIcon from "../assets/svg/role/event.svg";
|
|
4
|
+
import BookingIcon from "../assets/svg/role/booking.svg";
|
|
5
|
+
import EmailIcon from "../assets/svg/role/emails.svg";
|
|
6
|
+
import VenueIcon from "../assets/svg/role/venue.svg";
|
|
7
|
+
import PayoutIcon from "../assets/svg/role/payout.svg";
|
|
8
|
+
import MarketingIcon from "../assets/svg/role/marketing.svg";
|
|
9
|
+
import OrdersIcon from "../assets/svg/role/orders.svg";
|
|
10
|
+
import OrganisationIcon from "../assets/svg/role/organisation.svg";
|
|
11
|
+
import ReportingIcon from "../assets/svg/role/reporting.svg";
|
|
12
|
+
import microphonePlaceholder from "../assets/images/microphone.png";
|
|
13
|
+
|
|
14
|
+
export function classNames(...classes) {
|
|
15
|
+
return classes.filter(Boolean).join(" ");
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function truncateTitle(title, maxLength) {
|
|
19
|
+
if (title.length > maxLength) {
|
|
20
|
+
return title.slice(0, maxLength) + "...";
|
|
21
|
+
}
|
|
22
|
+
return title;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function convertToCustomDateFormat(isoString) {
|
|
26
|
+
const date = new Date(isoString);
|
|
27
|
+
|
|
28
|
+
const year = date.getUTCFullYear();
|
|
29
|
+
const month = date.getUTCMonth();
|
|
30
|
+
const day = date.getUTCDate();
|
|
31
|
+
|
|
32
|
+
const customDate = new Date(year, month, day);
|
|
33
|
+
|
|
34
|
+
return customDate;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function cn(...inputs) {
|
|
38
|
+
return twMerge(clsx(inputs));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function getDays(params) {
|
|
42
|
+
if (params === "weeks") {
|
|
43
|
+
return [
|
|
44
|
+
{ value: "monday", label: "Monday" },
|
|
45
|
+
{ value: "tuesday", label: "Tuesday" },
|
|
46
|
+
{ value: "wednesday", label: "Wednesday" },
|
|
47
|
+
{ value: "thursday", label: "Thursday" },
|
|
48
|
+
{ value: "friday", label: "Friday" },
|
|
49
|
+
];
|
|
50
|
+
} else {
|
|
51
|
+
return Array.from({ length: 31 }, (_, i) => {
|
|
52
|
+
const day = i + 1;
|
|
53
|
+
const suffix =
|
|
54
|
+
day % 10 === 1 && day !== 11
|
|
55
|
+
? "st"
|
|
56
|
+
: day % 10 === 2 && day !== 12
|
|
57
|
+
? "nd"
|
|
58
|
+
: day % 10 === 3 && day !== 13
|
|
59
|
+
? "rd"
|
|
60
|
+
: "th";
|
|
61
|
+
return {
|
|
62
|
+
value: day.toString(),
|
|
63
|
+
label: day + suffix,
|
|
64
|
+
};
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Function to get days number options based on selected time unit
|
|
70
|
+
export function getDaysNumberOptions(timeUnit) {
|
|
71
|
+
if (timeUnit === "months") {
|
|
72
|
+
return Array.from({ length: 12 }, (_, i) => ({
|
|
73
|
+
value: (i + 1).toString(),
|
|
74
|
+
label: (i + 1).toString(),
|
|
75
|
+
}));
|
|
76
|
+
} else if (timeUnit === "weeks") {
|
|
77
|
+
return Array.from({ length: 10 }, (_, i) => ({
|
|
78
|
+
value: (i + 1).toString(),
|
|
79
|
+
label: (i + 1).toString(),
|
|
80
|
+
}));
|
|
81
|
+
} else {
|
|
82
|
+
return Array.from({ length: 31 }, (_, i) => ({
|
|
83
|
+
value: (i + 1).toString(),
|
|
84
|
+
label: (i + 1).toString(),
|
|
85
|
+
}));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export const ROLE_PERMISSION_LIST = [
|
|
90
|
+
{
|
|
91
|
+
icon: EventIcon,
|
|
92
|
+
title: "Event creation",
|
|
93
|
+
description:
|
|
94
|
+
"Allow users to enter event info, create tickets & customize order forms",
|
|
95
|
+
checkbox: [
|
|
96
|
+
"Create Events",
|
|
97
|
+
"Edit Event Details",
|
|
98
|
+
"Manage event status",
|
|
99
|
+
"Manage tickets",
|
|
100
|
+
"Manage Collections",
|
|
101
|
+
],
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
icon: BookingIcon,
|
|
105
|
+
title: "Booking",
|
|
106
|
+
description:
|
|
107
|
+
"Allow users to manage performers, their invitations and statuses",
|
|
108
|
+
checkbox: [
|
|
109
|
+
"Access the roster page and view performer profiles",
|
|
110
|
+
"Edit performer profiles",
|
|
111
|
+
"Send booking invitations",
|
|
112
|
+
"Manually confirm/decline performers to spots",
|
|
113
|
+
"Send avails requests",
|
|
114
|
+
],
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
icon: VenueIcon,
|
|
118
|
+
title: "Venue creation",
|
|
119
|
+
description: "Allow users to create new venues",
|
|
120
|
+
checkbox: ["Add/edit/delete venues"],
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
icon: MarketingIcon,
|
|
124
|
+
title: "Marketing",
|
|
125
|
+
description:
|
|
126
|
+
"Sell more tickets by creating campaigns, tracking engagements, etc.",
|
|
127
|
+
checkbox: [
|
|
128
|
+
"Access social media posts",
|
|
129
|
+
"Manage tracking links",
|
|
130
|
+
"Manage promo codes",
|
|
131
|
+
],
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
icon: OrdersIcon,
|
|
135
|
+
title: "Orders & attendees",
|
|
136
|
+
description:
|
|
137
|
+
"Allow users to view, update & refund orders, manage attendee guest or waitlists & release tickets",
|
|
138
|
+
checkbox: [
|
|
139
|
+
"Add attendees",
|
|
140
|
+
"Manage orders, refunds, transfers and attendees",
|
|
141
|
+
"View list of attendees",
|
|
142
|
+
"Check in attendees",
|
|
143
|
+
"Resend confirmation emails",
|
|
144
|
+
"Override ticket restrictions",
|
|
145
|
+
"Sell tickets at the door",
|
|
146
|
+
"Revoke and reissue barcodes",
|
|
147
|
+
],
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
icon: OrganisationIcon,
|
|
151
|
+
title: "Organization",
|
|
152
|
+
description:
|
|
153
|
+
"Keep your users organized with assigned permissions per user, enable access to APIs & extensions",
|
|
154
|
+
checkbox: [
|
|
155
|
+
"Manage organization members & permissions",
|
|
156
|
+
"Edit organization infomation",
|
|
157
|
+
],
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
icon: EmailIcon,
|
|
161
|
+
title: "Contacts",
|
|
162
|
+
description:
|
|
163
|
+
"Keep our users in the loop, select which emails you would like them to receive",
|
|
164
|
+
checkbox: ["Email attendees", "Email/SMS performers"],
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
icon: ReportingIcon,
|
|
168
|
+
title: "Reporting",
|
|
169
|
+
description:
|
|
170
|
+
"Allow users to access, filter & export data across your organization",
|
|
171
|
+
checkbox: ["Access reports pages"],
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
icon: PayoutIcon,
|
|
175
|
+
title: "Payouts & billing",
|
|
176
|
+
description:
|
|
177
|
+
"Users can configure payout methods, manage event payment options & track financials with reporting",
|
|
178
|
+
checkbox: ["Manage financial accounts (Stripe)"],
|
|
179
|
+
},
|
|
180
|
+
];
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Parse a location string into street address and city/state/zip components
|
|
184
|
+
* @param {string} locationString - Full location string (e.g., "3400 Warner Blvd, Burbank, CA 91505")
|
|
185
|
+
* @returns {{street: string, cityStateZip: string}} Parsed location object
|
|
186
|
+
*/
|
|
187
|
+
export function parseLocation(locationString) {
|
|
188
|
+
if (!locationString) return { street: '', cityStateZip: '' };
|
|
189
|
+
|
|
190
|
+
// Split by comma to separate components
|
|
191
|
+
const parts = locationString.split(',').map(part => part.trim());
|
|
192
|
+
|
|
193
|
+
if (parts.length >= 3) {
|
|
194
|
+
// Format: "3400 Warner Blvd, Burbank, CA 91505"
|
|
195
|
+
const street = parts[0];
|
|
196
|
+
const cityStateZip = parts.slice(1).join(', ');
|
|
197
|
+
return { street, cityStateZip };
|
|
198
|
+
} else if (parts.length === 2) {
|
|
199
|
+
// Format: "Street, City State Zip"
|
|
200
|
+
return { street: parts[0], cityStateZip: parts[1] };
|
|
201
|
+
} else {
|
|
202
|
+
// Single part or unexpected format
|
|
203
|
+
return { street: locationString, cityStateZip: '' };
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Set authentication cookies with proper domain and security settings
|
|
209
|
+
* @param {string} token - Authentication token
|
|
210
|
+
* @param {Object} userDetails - User details object
|
|
211
|
+
*/
|
|
212
|
+
export function setAuthCookies(token, userDetails, rememberMe = true) {
|
|
213
|
+
const isProd = window.location.hostname.includes("get-micdrop.com");
|
|
214
|
+
const domainAttr = isProd ? "domain=.get-micdrop.com;" : "";
|
|
215
|
+
const secureAttr = window.location.protocol === "https:" ? "secure;" : "";
|
|
216
|
+
const maxAge = rememberMe ? "max-age=2592000;" : ""; // 30 days or session
|
|
217
|
+
|
|
218
|
+
document.cookie = `performer_token=${token}; path=/; ${maxAge} ${domainAttr} ${secureAttr} samesite=lax`;
|
|
219
|
+
document.cookie = `userDetails=${encodeURIComponent(
|
|
220
|
+
JSON.stringify(userDetails),
|
|
221
|
+
)}; path=/; ${maxAge} ${domainAttr} ${secureAttr} samesite=lax`;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Clear authentication cookies
|
|
226
|
+
*/
|
|
227
|
+
export function clearAuthCookies() {
|
|
228
|
+
const isProd = window.location.hostname.includes("get-micdrop.com");
|
|
229
|
+
const domainAttr = isProd ? "domain=.get-micdrop.com;" : "";
|
|
230
|
+
|
|
231
|
+
document.cookie = `userDetails=; path=/; max-age=0; ${domainAttr}`;
|
|
232
|
+
document.cookie = `performer_token=; path=/; max-age=0; ${domainAttr}`;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// Export microphone placeholder for universal event image fallback
|
|
236
|
+
export { microphonePlaceholder };
|
|
237
|
+
|
|
238
|
+
// ============================================
|
|
239
|
+
// COOKIE UTILITIES
|
|
240
|
+
// ============================================
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Parse all cookies into an object
|
|
244
|
+
* @returns {Record<string, string>} Cookie key-value pairs
|
|
245
|
+
*/
|
|
246
|
+
export function parseCookies() {
|
|
247
|
+
if (typeof document === "undefined") return {};
|
|
248
|
+
return document.cookie.split("; ").reduce((acc, cookie) => {
|
|
249
|
+
if (!cookie) return acc;
|
|
250
|
+
const [name, ...valueParts] = cookie.split("=");
|
|
251
|
+
acc[name] = decodeURIComponent(valueParts.join("="));
|
|
252
|
+
return acc;
|
|
253
|
+
}, {});
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Get a specific cookie value
|
|
258
|
+
* @param {string} name - Cookie name
|
|
259
|
+
* @returns {string|null} Cookie value or null
|
|
260
|
+
*/
|
|
261
|
+
export function getCookie(name) {
|
|
262
|
+
const cookies = parseCookies();
|
|
263
|
+
return cookies[name] || null;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Set a cookie with options
|
|
268
|
+
* @param {string} name - Cookie name
|
|
269
|
+
* @param {string} value - Cookie value
|
|
270
|
+
* @param {Object} options - Cookie options
|
|
271
|
+
*/
|
|
272
|
+
export function setCookie(name, value, options = {}) {
|
|
273
|
+
const isProd = typeof window !== "undefined" && window.location.hostname.includes("get-micdrop.com");
|
|
274
|
+
const domainAttr = isProd ? "domain=.get-micdrop.com;" : "";
|
|
275
|
+
const secureAttr = typeof window !== "undefined" && window.location.protocol === "https:" ? "secure;" : "";
|
|
276
|
+
const maxAge = options.maxAge ? `max-age=${options.maxAge};` : "";
|
|
277
|
+
const path = options.path || "/";
|
|
278
|
+
|
|
279
|
+
document.cookie = `${name}=${encodeURIComponent(value)}; path=${path}; ${maxAge} ${domainAttr} ${secureAttr} samesite=lax`;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Get the performer token from cookies
|
|
284
|
+
* @returns {string|null} Token or null
|
|
285
|
+
*/
|
|
286
|
+
export function getPerformerToken() {
|
|
287
|
+
return getCookie("performer_token");
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Get user details from cookies
|
|
292
|
+
* @returns {Object|null} User details or null
|
|
293
|
+
*/
|
|
294
|
+
export function getUserDetails() {
|
|
295
|
+
const details = getCookie("userDetails");
|
|
296
|
+
if (!details) return null;
|
|
297
|
+
try {
|
|
298
|
+
return JSON.parse(details);
|
|
299
|
+
} catch {
|
|
300
|
+
return null;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Get suppressed alerts from cookies
|
|
306
|
+
* @returns {string[]} Array of suppressed alert IDs
|
|
307
|
+
*/
|
|
308
|
+
export function getSuppressedAlerts() {
|
|
309
|
+
const alerts = getCookie("suppressedAlerts");
|
|
310
|
+
if (!alerts) return [];
|
|
311
|
+
try {
|
|
312
|
+
return JSON.parse(alerts);
|
|
313
|
+
} catch {
|
|
314
|
+
return [];
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Save suppressed alerts to cookies
|
|
320
|
+
* @param {string[]} alertIds - Array of alert IDs to suppress
|
|
321
|
+
*/
|
|
322
|
+
export function saveSuppressedAlerts(alertIds) {
|
|
323
|
+
setCookie("suppressedAlerts", JSON.stringify(alertIds), { maxAge: 31536000 }); // 1 year
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// ============================================
|
|
327
|
+
// DATA FETCHING UTILITIES
|
|
328
|
+
// ============================================
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* Fetch data from an API endpoint with error handling
|
|
332
|
+
* @param {string} endpoint - API endpoint
|
|
333
|
+
* @param {Object} options - Fetch options
|
|
334
|
+
* @returns {Promise<{data: any, error: string|null}>}
|
|
335
|
+
*/
|
|
336
|
+
export async function fetchData(endpoint, options = {}) {
|
|
337
|
+
try {
|
|
338
|
+
const res = await fetch(endpoint, {
|
|
339
|
+
headers: { "Content-Type": "application/json", ...options.headers },
|
|
340
|
+
...options,
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
if (!res.ok) {
|
|
344
|
+
const errorText = await res.text().catch(() => "Unknown error");
|
|
345
|
+
throw new Error(errorText || `Request failed with status ${res.status}`);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
const data = await res.json();
|
|
349
|
+
return { data, error: null };
|
|
350
|
+
} catch (err) {
|
|
351
|
+
return { data: null, error: err.message };
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Post data to an API endpoint
|
|
357
|
+
* @param {string} endpoint - API endpoint
|
|
358
|
+
* @param {Object} data - Data to post
|
|
359
|
+
* @returns {Promise<{data: any, error: string|null, ok: boolean}>}
|
|
360
|
+
*/
|
|
361
|
+
export async function postData(endpoint, data) {
|
|
362
|
+
try {
|
|
363
|
+
const res = await fetch(endpoint, {
|
|
364
|
+
method: "POST",
|
|
365
|
+
headers: { "Content-Type": "application/json" },
|
|
366
|
+
body: JSON.stringify(data),
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
const responseData = await res.json().catch(() => ({}));
|
|
17
370
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
371
|
+
return {
|
|
372
|
+
data: responseData,
|
|
373
|
+
error: res.ok ? null : (responseData.message || "Request failed"),
|
|
374
|
+
ok: res.ok
|
|
375
|
+
};
|
|
376
|
+
} catch (err) {
|
|
377
|
+
return { data: null, error: err.message, ok: false };
|
|
21
378
|
}
|
|
22
|
-
return title;
|
|
23
379
|
}
|
|
24
380
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const month = date.getUTCMonth();
|
|
30
|
-
const day = date.getUTCDate();
|
|
31
|
-
|
|
32
|
-
const customDate = new Date(year, month, day);
|
|
381
|
+
// ============================================
|
|
382
|
+
// DATE/TIME FORMATTING UTILITIES
|
|
383
|
+
// (Merged from utils/utils/utils.js)
|
|
384
|
+
// ============================================
|
|
33
385
|
|
|
34
|
-
|
|
386
|
+
export function convertToDate(value) {
|
|
387
|
+
return value ? new Date(value).toDateString() : null;
|
|
35
388
|
}
|
|
36
389
|
|
|
37
|
-
export function
|
|
38
|
-
|
|
390
|
+
export function convertToCustomDateTimeFormat(isoDateString) {
|
|
391
|
+
const date = new Date(isoDateString);
|
|
392
|
+
return new Date(
|
|
393
|
+
Date.UTC(
|
|
394
|
+
date.getUTCFullYear(),
|
|
395
|
+
date.getUTCMonth(),
|
|
396
|
+
date.getUTCDate(),
|
|
397
|
+
date.getUTCHours(),
|
|
398
|
+
date.getUTCMinutes()
|
|
399
|
+
)
|
|
400
|
+
);
|
|
39
401
|
}
|
|
40
402
|
|
|
41
|
-
export function
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
{ value: "thursday", label: "Thursday" },
|
|
48
|
-
{ value: "friday", label: "Friday" },
|
|
49
|
-
];
|
|
50
|
-
} else {
|
|
51
|
-
return Array.from({ length: 31 }, (_, i) => {
|
|
52
|
-
const day = i + 1;
|
|
53
|
-
const suffix =
|
|
54
|
-
day % 10 === 1 && day !== 11
|
|
55
|
-
? "st"
|
|
56
|
-
: day % 10 === 2 && day !== 12
|
|
57
|
-
? "nd"
|
|
58
|
-
: day % 10 === 3 && day !== 13
|
|
59
|
-
? "rd"
|
|
60
|
-
: "th";
|
|
61
|
-
return {
|
|
62
|
-
value: day.toString(),
|
|
63
|
-
label: day + suffix,
|
|
64
|
-
};
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
}
|
|
403
|
+
export function formatHour(dateString) {
|
|
404
|
+
const date = new Date(dateString);
|
|
405
|
+
const hour = date.getUTCHours();
|
|
406
|
+
const minutes = date.getUTCMinutes();
|
|
407
|
+
const suffix = hour >= 12 ? "PM" : "AM";
|
|
408
|
+
const displayHour = hour % 12 || 12;
|
|
68
409
|
|
|
69
|
-
//
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
value: (i + 1).toString(),
|
|
74
|
-
label: (i + 1).toString(),
|
|
75
|
-
}));
|
|
76
|
-
} else if (timeUnit === "weeks") {
|
|
77
|
-
return Array.from({ length: 10 }, (_, i) => ({
|
|
78
|
-
value: (i + 1).toString(),
|
|
79
|
-
label: (i + 1).toString(),
|
|
80
|
-
}));
|
|
81
|
-
} else {
|
|
82
|
-
return Array.from({ length: 31 }, (_, i) => ({
|
|
83
|
-
value: (i + 1).toString(),
|
|
84
|
-
label: (i + 1).toString(),
|
|
85
|
-
}));
|
|
86
|
-
}
|
|
410
|
+
// Ensure minutes are always two digits
|
|
411
|
+
const displayMinutes = minutes < 10 ? "0" + minutes : minutes;
|
|
412
|
+
|
|
413
|
+
return `${displayHour}:${displayMinutes} ${suffix}`;
|
|
87
414
|
}
|
|
88
415
|
|
|
89
|
-
export
|
|
90
|
-
{
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
checkbox: [
|
|
96
|
-
"Create Events",
|
|
97
|
-
"Edit Event Details",
|
|
98
|
-
"Manage event status",
|
|
99
|
-
"Manage tickets",
|
|
100
|
-
"Manage Collections",
|
|
101
|
-
],
|
|
102
|
-
},
|
|
103
|
-
{
|
|
104
|
-
icon: BookingIcon,
|
|
105
|
-
title: "Booking",
|
|
106
|
-
description:
|
|
107
|
-
"Allow users to manage performers, their invitations and statuses",
|
|
108
|
-
checkbox: [
|
|
109
|
-
"Access the roster page and view performer profiles",
|
|
110
|
-
"Edit performer profiles",
|
|
111
|
-
"Send booking invitations",
|
|
112
|
-
"Manually confirm/decline performers to spots",
|
|
113
|
-
"Send avails requests",
|
|
114
|
-
],
|
|
115
|
-
},
|
|
116
|
-
{
|
|
117
|
-
icon: VenueIcon,
|
|
118
|
-
title: "Venue creation",
|
|
119
|
-
description: "Allow users to create new venues",
|
|
120
|
-
checkbox: ["Add/edit/delete venues"],
|
|
121
|
-
},
|
|
122
|
-
{
|
|
123
|
-
icon: MarketingIcon,
|
|
124
|
-
title: "Marketing",
|
|
125
|
-
description:
|
|
126
|
-
"Sell more tickets by creating campaigns, tracking engagements, etc.",
|
|
127
|
-
checkbox: [
|
|
128
|
-
"Access social media posts",
|
|
129
|
-
"Manage tracking links",
|
|
130
|
-
"Manage promo codes",
|
|
131
|
-
],
|
|
132
|
-
},
|
|
133
|
-
{
|
|
134
|
-
icon: OrdersIcon,
|
|
135
|
-
title: "Orders & attendees",
|
|
136
|
-
description:
|
|
137
|
-
"Allow users to view, update & refund orders, manage attendee guest or waitlists & release tickets",
|
|
138
|
-
checkbox: [
|
|
139
|
-
"Add attendees",
|
|
140
|
-
"Manage orders, refunds, transfers and attendees",
|
|
141
|
-
"View list of attendees",
|
|
142
|
-
"Check in attendees",
|
|
143
|
-
"Resend confirmation emails",
|
|
144
|
-
"Override ticket restrictions",
|
|
145
|
-
"Sell tickets at the door",
|
|
146
|
-
"Revoke and reissue barcodes",
|
|
147
|
-
],
|
|
148
|
-
},
|
|
149
|
-
{
|
|
150
|
-
icon: OrganisationIcon,
|
|
151
|
-
title: "Organization",
|
|
152
|
-
description:
|
|
153
|
-
"Keep your users organized with assigned permissions per user, enable access to APIs & extensions",
|
|
154
|
-
checkbox: [
|
|
155
|
-
"Manage organization members & permissions",
|
|
156
|
-
"Edit organization infomation",
|
|
157
|
-
],
|
|
158
|
-
},
|
|
159
|
-
{
|
|
160
|
-
icon: EmailIcon,
|
|
161
|
-
title: "Contacts",
|
|
162
|
-
description:
|
|
163
|
-
"Keep our users in the loop, select which emails you would like them to receive",
|
|
164
|
-
checkbox: ["Email attendees", "Email/SMS performers"],
|
|
165
|
-
},
|
|
166
|
-
{
|
|
167
|
-
icon: ReportingIcon,
|
|
168
|
-
title: "Reporting",
|
|
169
|
-
description:
|
|
170
|
-
"Allow users to access, filter & export data across your organization",
|
|
171
|
-
checkbox: ["Access reports pages"],
|
|
172
|
-
},
|
|
173
|
-
{
|
|
174
|
-
icon: PayoutIcon,
|
|
175
|
-
title: "Payouts & billing",
|
|
176
|
-
description:
|
|
177
|
-
"Users can configure payout methods, manage event payment options & track financials with reporting",
|
|
178
|
-
checkbox: ["Manage financial accounts (Stripe)"],
|
|
179
|
-
},
|
|
180
|
-
];
|
|
416
|
+
export function formattedDate(date) {
|
|
417
|
+
const options = {
|
|
418
|
+
weekday: "short", // 'Thu'
|
|
419
|
+
month: "short", // 'Oct'
|
|
420
|
+
day: "2-digit", // '24'
|
|
421
|
+
};
|
|
181
422
|
|
|
182
|
-
|
|
183
|
-
* Parse a location string into street address and city/state/zip components
|
|
184
|
-
* @param {string} locationString - Full location string (e.g., "3400 Warner Blvd, Burbank, CA 91505")
|
|
185
|
-
* @returns {{street: string, cityStateZip: string}} Parsed location object
|
|
186
|
-
*/
|
|
187
|
-
export function parseLocation(locationString) {
|
|
188
|
-
if (!locationString) return { street: '', cityStateZip: '' };
|
|
189
|
-
|
|
190
|
-
// Split by comma to separate components
|
|
191
|
-
const parts = locationString.split(',').map(part => part.trim());
|
|
192
|
-
|
|
193
|
-
if (parts.length >= 3) {
|
|
194
|
-
// Format: "3400 Warner Blvd, Burbank, CA 91505"
|
|
195
|
-
const street = parts[0];
|
|
196
|
-
const cityStateZip = parts.slice(1).join(', ');
|
|
197
|
-
return { street, cityStateZip };
|
|
198
|
-
} else if (parts.length === 2) {
|
|
199
|
-
// Format: "Street, City State Zip"
|
|
200
|
-
return { street: parts[0], cityStateZip: parts[1] };
|
|
201
|
-
} else {
|
|
202
|
-
// Single part or unexpected format
|
|
203
|
-
return { street: locationString, cityStateZip: '' };
|
|
204
|
-
}
|
|
423
|
+
return new Date(date).toLocaleDateString("en-US", options);
|
|
205
424
|
}
|
|
206
425
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
document.cookie = `performer_token=${token}; path=/; ${maxAge} ${domainAttr} ${secureAttr} samesite=lax`;
|
|
221
|
-
document.cookie = `userDetails=${encodeURIComponent(
|
|
222
|
-
JSON.stringify(userDetails),
|
|
223
|
-
)}; path=/; ${maxAge} ${domainAttr} ${secureAttr} samesite=lax`;
|
|
224
|
-
|
|
225
|
-
// Store refresh token if provided (Keycloak integration)
|
|
226
|
-
if (refreshToken) {
|
|
227
|
-
document.cookie = `performer_refresh_token=${refreshToken}; path=/; ${maxAge} ${domainAttr} ${secureAttr} samesite=lax`;
|
|
426
|
+
// Helper function to get the ordinal suffix (st, nd, rd, th)
|
|
427
|
+
function getOrdinalSuffix(day) {
|
|
428
|
+
if (day >= 11 && day <= 13) return "th"; // Special case for 11th, 12th, and 13th
|
|
429
|
+
switch (day % 10) {
|
|
430
|
+
case 1:
|
|
431
|
+
return "st";
|
|
432
|
+
case 2:
|
|
433
|
+
return "nd";
|
|
434
|
+
case 3:
|
|
435
|
+
return "rd";
|
|
436
|
+
default:
|
|
437
|
+
return "th";
|
|
228
438
|
}
|
|
229
439
|
}
|
|
230
440
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
document.cookie = `userDetails=; path=/; max-age=0; ${domainAttr}`;
|
|
239
|
-
document.cookie = `performer_token=; path=/; max-age=0; ${domainAttr}`;
|
|
240
|
-
document.cookie = `performer_refresh_token=; path=/; max-age=0; ${domainAttr}`;
|
|
241
|
-
}
|
|
441
|
+
export function formattedFullDate(date) {
|
|
442
|
+
const options = {
|
|
443
|
+
weekday: "long", // 'Thursday'
|
|
444
|
+
month: "long", // 'October'
|
|
445
|
+
day: "numeric", // '24'
|
|
446
|
+
year: "numeric", // '2024'
|
|
447
|
+
};
|
|
242
448
|
|
|
243
|
-
|
|
244
|
-
export { microphonePlaceholder };
|
|
449
|
+
const formattedDate = new Date(date).toLocaleDateString("en-US", options);
|
|
245
450
|
|
|
246
|
-
//
|
|
247
|
-
|
|
248
|
-
|
|
451
|
+
// Get the day of the month to append the ordinal suffix
|
|
452
|
+
const day = new Date(date).getDate();
|
|
453
|
+
const ordinalSuffix = getOrdinalSuffix(day);
|
|
249
454
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
*/
|
|
254
|
-
export function parseCookies() {
|
|
255
|
-
if (typeof document === "undefined") return {};
|
|
256
|
-
return document.cookie.split("; ").reduce((acc, cookie) => {
|
|
257
|
-
if (!cookie) return acc;
|
|
258
|
-
const [name, ...valueParts] = cookie.split("=");
|
|
259
|
-
acc[name] = decodeURIComponent(valueParts.join("="));
|
|
260
|
-
return acc;
|
|
261
|
-
}, {});
|
|
455
|
+
// Replace the day number with the day + ordinal suffix
|
|
456
|
+
const fullDate = formattedDate.replace(/\d+/, day + ordinalSuffix);
|
|
457
|
+
return fullDate;
|
|
262
458
|
}
|
|
263
459
|
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
460
|
+
export const formatDateTime = (dateTimeString, timeZone = "UTC") => {
|
|
461
|
+
const options = {
|
|
462
|
+
weekday: "short", // Mon, Tue, etc.
|
|
463
|
+
year: "numeric", // 2024
|
|
464
|
+
month: "short", // Dec
|
|
465
|
+
day: "numeric", // 12
|
|
466
|
+
hour: "numeric", // 11
|
|
467
|
+
minute: "numeric", // 00
|
|
468
|
+
hour12: true, // 11:00 PM format
|
|
469
|
+
timeZone: timeZone, // Account for the timezone, defaults to 'UTC'
|
|
470
|
+
};
|
|
471
|
+
|
|
472
|
+
const date = new Date(dateTimeString);
|
|
473
|
+
|
|
474
|
+
return new Intl.DateTimeFormat("en-US", options).format(date);
|
|
475
|
+
};
|
|
476
|
+
|
|
477
|
+
export const formatTimeline = (startDateTime) => {
|
|
478
|
+
const formatHourInternal = (date) => {
|
|
479
|
+
let hours = date.getUTCHours();
|
|
480
|
+
const minutes = date.getUTCMinutes();
|
|
481
|
+
const suffix = hours >= 12 ? "PM" : "AM";
|
|
482
|
+
hours = hours % 12 || 12;
|
|
483
|
+
|
|
484
|
+
return `${hours}:${minutes < 10 ? "0" + minutes : minutes} ${suffix}`;
|
|
485
|
+
};
|
|
486
|
+
|
|
487
|
+
const start = formatHourInternal(new Date(startDateTime));
|
|
488
|
+
return `${start}`;
|
|
489
|
+
};
|
|
490
|
+
|
|
491
|
+
export function formatTimeRange(startDate, endDate) {
|
|
492
|
+
const start = new Date(startDate);
|
|
493
|
+
const end = new Date(endDate);
|
|
494
|
+
|
|
495
|
+
function formatTime(date) {
|
|
496
|
+
let hours = date.getUTCHours();
|
|
497
|
+
const minutes = date.getUTCMinutes();
|
|
498
|
+
const ampm = hours >= 12 ? "PM" : "AM";
|
|
499
|
+
hours = hours % 12;
|
|
500
|
+
hours = hours ? hours : 12;
|
|
501
|
+
const minutesStr = minutes < 10 ? "0" + minutes : minutes;
|
|
502
|
+
return hours + ":" + minutesStr + " " + ampm;
|
|
503
|
+
}
|
|
504
|
+
const startTime = formatTime(start);
|
|
505
|
+
const endTime = formatTime(end);
|
|
506
|
+
return `${startTime} - ${endTime}`;
|
|
272
507
|
}
|
|
273
508
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
* @param {string} value - Cookie value
|
|
278
|
-
* @param {Object} options - Cookie options
|
|
279
|
-
*/
|
|
280
|
-
export function setCookie(name, value, options = {}) {
|
|
281
|
-
const isProd = typeof window !== "undefined" && window.location.hostname.includes("get-micdrop.com");
|
|
282
|
-
const domainAttr = isProd ? "domain=.get-micdrop.com;" : "";
|
|
283
|
-
const secureAttr = typeof window !== "undefined" && window.location.protocol === "https:" ? "secure;" : "";
|
|
284
|
-
const maxAge = options.maxAge ? `max-age=${options.maxAge};` : "";
|
|
285
|
-
const path = options.path || "/";
|
|
286
|
-
|
|
287
|
-
document.cookie = `${name}=${encodeURIComponent(value)}; path=${path}; ${maxAge} ${domainAttr} ${secureAttr} samesite=lax`;
|
|
288
|
-
}
|
|
509
|
+
export function getDateRange(startDate, endDate) {
|
|
510
|
+
const start = new Date(startDate);
|
|
511
|
+
const end = new Date(endDate);
|
|
289
512
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
* @returns {string|null} Token or null
|
|
293
|
-
*/
|
|
294
|
-
export function getPerformerToken() {
|
|
295
|
-
return getCookie("performer_token");
|
|
296
|
-
}
|
|
513
|
+
const dateArray = [];
|
|
514
|
+
const currentDate = new Date(start);
|
|
297
515
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
if (!details) return null;
|
|
305
|
-
try {
|
|
306
|
-
return JSON.parse(details);
|
|
307
|
-
} catch {
|
|
308
|
-
return null;
|
|
516
|
+
while (currentDate <= end) {
|
|
517
|
+
dateArray.push(
|
|
518
|
+
`${currentDate.getUTCFullYear()}-${currentDate.getUTCMonth() + 1
|
|
519
|
+
}-${currentDate.getUTCDate()}`
|
|
520
|
+
);
|
|
521
|
+
currentDate.setUTCDate(currentDate.getUTCDate() + 1); // Move to the next day
|
|
309
522
|
}
|
|
310
|
-
}
|
|
311
523
|
|
|
312
|
-
|
|
313
|
-
* Get suppressed alerts from cookies
|
|
314
|
-
* @returns {string[]} Array of suppressed alert IDs
|
|
315
|
-
*/
|
|
316
|
-
export function getSuppressedAlerts() {
|
|
317
|
-
const alerts = getCookie("suppressedAlerts");
|
|
318
|
-
if (!alerts) return [];
|
|
319
|
-
try {
|
|
320
|
-
return JSON.parse(alerts);
|
|
321
|
-
} catch {
|
|
322
|
-
return [];
|
|
323
|
-
}
|
|
524
|
+
return dateArray;
|
|
324
525
|
}
|
|
325
526
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
527
|
+
export const getDay = (dateString) => {
|
|
528
|
+
const days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
|
529
|
+
const date = new Date(dateString);
|
|
530
|
+
return days[date.getUTCDay()];
|
|
531
|
+
};
|
|
532
|
+
|
|
533
|
+
export const getMonth = (dateString) => {
|
|
534
|
+
const months = [
|
|
535
|
+
"Jan",
|
|
536
|
+
"Feb",
|
|
537
|
+
"Mar",
|
|
538
|
+
"Apr",
|
|
539
|
+
"May",
|
|
540
|
+
"Jun",
|
|
541
|
+
"Jul",
|
|
542
|
+
"Aug",
|
|
543
|
+
"Sep",
|
|
544
|
+
"Oct",
|
|
545
|
+
"Nov",
|
|
546
|
+
"Dec",
|
|
547
|
+
];
|
|
548
|
+
const date = new Date(dateString);
|
|
549
|
+
return months[date.getUTCMonth()];
|
|
550
|
+
};
|
|
551
|
+
|
|
552
|
+
export const getDateOfMonth = (dateString) => {
|
|
553
|
+
const date = new Date(dateString);
|
|
554
|
+
return date.getUTCDate();
|
|
555
|
+
};
|
|
333
556
|
|
|
334
557
|
// ============================================
|
|
335
|
-
//
|
|
558
|
+
// EVENT FORMATTING UTILITIES
|
|
336
559
|
// ============================================
|
|
337
560
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
561
|
+
// Map roleOnStage numeric value to role name string
|
|
562
|
+
// These correspond to the lineup position roles in the operator panel
|
|
563
|
+
const ROLE_ON_STAGE_MAP = {
|
|
564
|
+
0: "Performer",
|
|
565
|
+
1: "Host",
|
|
566
|
+
2: "Headliner",
|
|
567
|
+
3: "Feature",
|
|
568
|
+
4: "Special Guest",
|
|
569
|
+
5: "Opener",
|
|
570
|
+
6: "Guest",
|
|
571
|
+
7: "Teacher",
|
|
572
|
+
8: "Assistant",
|
|
573
|
+
};
|
|
574
|
+
|
|
575
|
+
export const getRoleFromRoleOnStage = (roleOnStage) => {
|
|
576
|
+
return ROLE_ON_STAGE_MAP[roleOnStage] || "Performer";
|
|
577
|
+
};
|
|
578
|
+
|
|
579
|
+
// Format Event as Show for Listing data
|
|
580
|
+
export const formatEvent = (event) => {
|
|
581
|
+
// Get venue stage name (the physical stage at the venue, e.g., "Main Room", "Showroom")
|
|
582
|
+
// Not to be confused with performer's stage name (their performance alias)
|
|
583
|
+
const venueStageName = event.Event.stage?.name || event.Event.stage?.googleName || event.Event.googleName || "";
|
|
584
|
+
|
|
585
|
+
// Handle potentially undefined venue address
|
|
586
|
+
const venueAddress = event.Event.venue.address || "";
|
|
587
|
+
|
|
588
|
+
// Map roleOnStage number to role name string
|
|
589
|
+
const role = getRoleFromRoleOnStage(event.roleOnStage);
|
|
590
|
+
|
|
591
|
+
// Get custom booking notification message from venue (set in venue edit page)
|
|
592
|
+
const bookingMessage = event.Event.venue.booking_notification || "No additional details available.";
|
|
593
|
+
|
|
594
|
+
return {
|
|
595
|
+
eventId: event.Event.ID,
|
|
596
|
+
venueId: event.Event.venue.ID,
|
|
597
|
+
title: event.Event.title,
|
|
598
|
+
role: role,
|
|
599
|
+
startDateTime: event.Event.startDateTime,
|
|
600
|
+
acceptedState: event.acceptedState,
|
|
601
|
+
doorsOpenTime: event.Event.doorsOpenTime,
|
|
602
|
+
spotDuration: `${event.setLength} min spot`,
|
|
603
|
+
venueName: event.Event.venue.name,
|
|
604
|
+
location: venueAddress,
|
|
605
|
+
id: event.invitationId,
|
|
606
|
+
image: event.Event.image,
|
|
607
|
+
details: {
|
|
608
|
+
venue: event.Event.venue.name,
|
|
609
|
+
stageName: venueStageName,
|
|
610
|
+
address: venueAddress,
|
|
611
|
+
setLength: `${event.setLength} min`,
|
|
612
|
+
eventDetails: bookingMessage,
|
|
613
|
+
},
|
|
614
|
+
lastUpdated: event.UpdatedAt,
|
|
615
|
+
};
|
|
616
|
+
};
|
|
617
|
+
|
|
618
|
+
export const formatRosterEventPerformerInvite = (event) => {
|
|
619
|
+
return {
|
|
620
|
+
venueId: event.venueId,
|
|
621
|
+
role: event.role || "Performer",
|
|
622
|
+
acceptedState: event.acceptedState,
|
|
623
|
+
name: event.Venue.name,
|
|
624
|
+
shortVenue: `${event.Venue.firstName} ${event.Venue.lastName} - ${event.Venue.role}`,
|
|
625
|
+
location: `${event.Venue.address}`,
|
|
626
|
+
id: event.invitationId,
|
|
627
|
+
lastUpdated: event.UpdatedAt,
|
|
628
|
+
image: event.Venue.image,
|
|
629
|
+
hasAvailability: true,
|
|
630
|
+
invitationAccepted: event.acceptedState === 2,
|
|
631
|
+
};
|
|
632
|
+
};
|
|
633
|
+
|
|
634
|
+
export const formatVenue = (event) => {
|
|
635
|
+
return {
|
|
636
|
+
venueId: event.Event.venueId,
|
|
637
|
+
name: event.Event.venue.name,
|
|
638
|
+
image: event.Event.venue.squareImageUrl || event.Event.venue.image,
|
|
639
|
+
location: `${event.Event.venue.address}`,
|
|
640
|
+
start: event.Event.startDateTime,
|
|
641
|
+
end: event.Event.endDateTime,
|
|
642
|
+
doorOpen: event.Event.doorsOpenTime,
|
|
643
|
+
email: event.Event.venue.email,
|
|
644
|
+
phone: event.Event.venue.phone,
|
|
645
|
+
description: event.Event.venue.description,
|
|
646
|
+
instagram: event.Event.venue.instagram,
|
|
647
|
+
facebook: event.Event.venue.facebook,
|
|
648
|
+
twitter: event.Event.venue.twitter,
|
|
649
|
+
lastUpdated: event.UpdatedAt,
|
|
650
|
+
timeRange: formatTimeRange(event.Event.startDateTime, event.Event.endDateTime),
|
|
651
|
+
dateRange: getDateRange(event.Event.startDateTime, event.Event.endDateTime),
|
|
652
|
+
};
|
|
653
|
+
};
|
|
350
654
|
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
}
|
|
655
|
+
// ============================================
|
|
656
|
+
// STRING UTILITIES
|
|
657
|
+
// ============================================
|
|
355
658
|
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
} catch (err) {
|
|
359
|
-
return { data: null, error: err.message };
|
|
360
|
-
}
|
|
659
|
+
export function capitalize(word) {
|
|
660
|
+
return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
|
|
361
661
|
}
|
|
362
662
|
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
return {
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
}
|
|
384
|
-
} catch (err) {
|
|
385
|
-
return { data: null, error: err.message, ok: false };
|
|
663
|
+
export function timeAgo(date) {
|
|
664
|
+
const now = new Date();
|
|
665
|
+
const seconds = Math.floor((now - new Date(date)) / 1000);
|
|
666
|
+
const minutes = Math.floor(seconds / 60);
|
|
667
|
+
const hours = Math.floor(minutes / 60);
|
|
668
|
+
const days = Math.floor(hours / 24);
|
|
669
|
+
const months = Math.floor(days / 30);
|
|
670
|
+
const years = Math.floor(months / 12);
|
|
671
|
+
|
|
672
|
+
if (seconds < 60) {
|
|
673
|
+
return `${seconds} second${seconds !== 1 ? "s" : ""} ago`;
|
|
674
|
+
} else if (minutes < 60) {
|
|
675
|
+
return `${minutes} minute${minutes !== 1 ? "s" : ""} ago`;
|
|
676
|
+
} else if (hours < 24) {
|
|
677
|
+
return `${hours} hour${hours !== 1 ? "s" : ""} ago`;
|
|
678
|
+
} else if (days < 30) {
|
|
679
|
+
return `${days} day${days !== 1 ? "s" : ""} ago`;
|
|
680
|
+
} else if (months < 12) {
|
|
681
|
+
return `${months} month${months !== 1 ? "s" : ""} ago`;
|
|
682
|
+
} else {
|
|
683
|
+
return `${years} year${years !== 1 ? "s" : ""} ago`;
|
|
386
684
|
}
|
|
387
685
|
}
|