Skip to content

Commit 800fe41

Browse files
committed
fixed a lot of ESLint issues
1 parent 0a134c5 commit 800fe41

9 files changed

Lines changed: 80 additions & 157 deletions

File tree

bun.lock

Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@
105105
"qs": ">=6.14.1"
106106
},
107107
"overrides": {
108-
"brace-expansion": "1.1.11",
109108
"fast-uri": "^3.1.3",
110109
"immutable": "^5.1.8",
111110
"postcss": "^8.5.25",
@@ -126,6 +125,7 @@
126125
"@parcel/watcher",
127126
"core-js",
128127
"noblox.js",
129-
"unrs-resolver"
128+
"unrs-resolver",
129+
"brace-expansion"
130130
]
131131
}

pages/workspace/[id]/sessions.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,10 @@ export const getServerSideProps = withPermissionCheckSsr(
154154
if (user && user.roles?.[0] && !isAdmin) {
155155
const role = user.roles[0];
156156
const sessionTypes = ["shift", "training", "event", "other"];
157-
const visibleTypes = sessionTypes.filter(type =>
157+
const visibleTypes = sessionTypes.filter(type =>
158158
role.permissions.includes(`sessions_${type}_see`)
159159
);
160-
160+
161161
if (visibleTypes.length > 0) {
162162
filteredSessions = allSessions.filter((session) =>
163163
visibleTypes.includes(session.type || "other")
@@ -675,7 +675,7 @@ const Home: pageWithLayout<pageProps> = (props) => {
675675

676676
const handleEditSession = async (sessionId: string) => {
677677
const session = allSessions.find(s => s.id === sessionId);
678-
678+
679679
if (session?.scheduleId) {
680680
setSessionToEdit(session);
681681
setIsPatternEditDialogOpen(true);
@@ -745,7 +745,7 @@ const Home: pageWithLayout<pageProps> = (props) => {
745745
);
746746
return [...otherDateSessions, ...sessions];
747747
});
748-
748+
749749
return sessions;
750750
} catch (error) {
751751
console.error("Failed to load sessions:", error);
@@ -761,13 +761,13 @@ const Home: pageWithLayout<pageProps> = (props) => {
761761
setHasInitialLoad(true);
762762
return;
763763
}
764-
764+
765765
if (router.query.id && selectedDate && !loading) {
766766
loadSessionsForDate(selectedDate);
767767
setHasInitialLoad(true);
768768
}
769769
}, [router.query.id, selectedDate, showHistory]);
770-
770+
771771
useEffect(() => {
772772
const newWeekDates = getWeekDates(getMonday(currentWeek));
773773
const today = new Date();
@@ -781,7 +781,7 @@ const Home: pageWithLayout<pageProps> = (props) => {
781781
setSelectedDate(newWeekDates[0]);
782782
}
783783
}, [currentWeek]);
784-
784+
785785
useEffect(() => {
786786
if (router.query.refresh === "true" && selectedDate) {
787787
loadSessionsForDate(selectedDate);

pages/workspace/[id]/sessions/edit/[sid].tsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@ const EditSession: pageWithLayout<
241241
const newDate = new Date(localDateTime);
242242

243243
// Prevent updating a session to a past date/time
244-
if (newDate.getTime() <= Date.now()) {
244+
const now = new Date();
245+
if (newDate.getTime() <= now.getTime()) {
245246
setFormError("Cannot set session date/time in the past. Choose a future date/time.");
246247
setIsSubmitting(false);
247248
setShowUpdateModal(false);
@@ -263,9 +264,9 @@ const EditSession: pageWithLayout<
263264
newName: formData.name,
264265
}
265266
);
266-
267+
267268
toast.success(
268-
scope === "single"
269+
scope === "single"
269270
? "Session updated successfully"
270271
: scope === "future"
271272
? "This and future sessions updated successfully"
@@ -290,7 +291,7 @@ const EditSession: pageWithLayout<
290291

291292
toast.success("Session updated successfully");
292293
}
293-
294+
294295
router.push(`/workspace/${workspace.groupId}/sessions`);
295296
} catch (err: any) {
296297
setFormError(
@@ -325,23 +326,23 @@ const EditSession: pageWithLayout<
325326
try {
326327
// If we have a scope from the pattern dialog, use it instead of asking again
327328
const deleteScope = scope || (deleteAll ? "all" : "single");
328-
329+
329330
await axios.delete(
330331
`/api/workspace/${workspace.groupId}/sessions/${session.id}/delete`,
331332
{
332-
data: {
333+
data: {
333334
deleteAll: deleteScope === "all",
334335
deleteScope: deleteScope, // Pass the scope for future/single distinction
335336
},
336337
}
337338
);
338-
339-
const successMessage = deleteScope === "single"
339+
340+
const successMessage = deleteScope === "single"
340341
? "Session deleted successfully"
341342
: deleteScope === "future"
342343
? "This and future sessions deleted successfully"
343344
: "All sessions in series deleted successfully";
344-
345+
345346
toast.success(successMessage);
346347
router.push(`/workspace/${workspace.groupId}/sessions`);
347348
} catch (err: any) {

pages/workspace/[id]/sessions/new.tsx

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,10 @@ const Home: pageWithLayout<InferGetServerSidePropsType<GetServerSideProps>> = ({
160160
const hasUnscheduledPerm = canCreateUnscheduled(workspace.yourPermission || [], type.value);
161161
return hasScheduledPerm || hasUnscheduledPerm;
162162
});
163-
const canCreateAnyScheduled = availableSessionTypes.some(type =>
163+
const canCreateAnyScheduled = availableSessionTypes.some(type =>
164164
canCreateScheduled(workspace.yourPermission || [], type.value)
165165
);
166-
const canCreateAnyUnscheduled = availableSessionTypes.some(type =>
166+
const canCreateAnyUnscheduled = availableSessionTypes.some(type =>
167167
canCreateUnscheduled(workspace.yourPermission || [], type.value)
168168
);
169169

@@ -278,7 +278,7 @@ const Home: pageWithLayout<InferGetServerSidePropsType<GetServerSideProps>> = ({
278278
const [localHours, localMinutes] = timeValue.split(":").map(Number);
279279
return { hours: localHours, minutes: localMinutes };
280280
});
281-
281+
282282
await axios.post(
283283
`/api/workspace/${workspace.groupId}/sessions/create-scheduled`,
284284
{
@@ -307,7 +307,7 @@ const Home: pageWithLayout<InferGetServerSidePropsType<GetServerSideProps>> = ({
307307
const [localHours, localMinutes] = timeValue.split(":").map(Number);
308308
return { hours: localHours, minutes: localMinutes };
309309
});
310-
310+
311311
await axios.post(`/api/workspace/${workspace.groupId}/sessions/create-scheduled`, {
312312
sessionTypeId: createdSessionType.id,
313313
name: form.getValues().name,
@@ -328,7 +328,14 @@ const Home: pageWithLayout<InferGetServerSidePropsType<GetServerSideProps>> = ({
328328
);
329329

330330
// Prevent creating sessions in the past
331-
if (localDateTime.getTime() <= Date.now()) {
331+
//if (localDateTime.getTime() <= Date.now()) {
332+
// setFormError("Cannot create a session in the past. Choose a future date/time.");
333+
// setIsSubmitting(false);
334+
// return;
335+
//}
336+
// Date.now is impure, so we use a different solution
337+
const now = new Date();
338+
if (localDateTime.getTime() <= now.getTime()) {
332339
setFormError("Cannot create a session in the past. Choose a future date/time.");
333340
setIsSubmitting(false);
334341
return;
@@ -409,7 +416,7 @@ const Home: pageWithLayout<InferGetServerSidePropsType<GetServerSideProps>> = ({
409416
} catch (err: any) {
410417
console.log("Creation completed with note:", err);
411418
}
412-
419+
413420
setPendingCreation(null);
414421
setShowOverlapModal(false);
415422
setTimeout(() => {
@@ -809,7 +816,7 @@ const Home: pageWithLayout<InferGetServerSidePropsType<GetServerSideProps>> = ({
809816
}}
810817
/>
811818
<p className="text-xs text-zinc-500 dark:text-zinc-400 ml-10">
812-
{canCreateAnyUnscheduled
819+
{canCreateAnyUnscheduled
813820
? "Enable this to set up a one time session"
814821
: "You don't have permission to create unscheduled sessions"}
815822
</p>

pages/workspace/[id]/settings.tsx

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -299,23 +299,21 @@ const Settings: pageWithLayout<Props> = ({
299299
isAdmin,
300300
userPermissions,
301301
}) => {
302-
const [activeSection, setActiveSection] = useState("general");
302+
//const [activeSection, setActiveSection] = useState("general");
303303
const [isSidebarExpanded] = useState(true);
304304

305305
const hasPermission = (permission: string) => {
306306
return isAdmin || userPermissions.includes(permission);
307307
};
308308

309309
const router = useRouter();
310+
const urlTab = decodeTab(router.query.t as string | null);
310311

311-
useEffect(() => {
312-
const t = router.query.t as string | undefined;
313-
const decoded = decodeTab(t ?? null);
314-
315-
if (decoded && SECTIONS[decoded as keyof typeof SECTIONS]) {
316-
setActiveSection(decoded);
317-
}
318-
}, [router.query.t]);
312+
const [activeSection, setActiveSection] = useState(
313+
urlTab && SECTIONS[urlTab as keyof typeof SECTIONS]
314+
? urlTab
315+
: "general",
316+
);
319317

320318
const canAccessGeneral = hasPermission("workspace_customisation");
321319
const canAccessActivity = hasPermission("reset_activity");
@@ -341,20 +339,13 @@ const Settings: pageWithLayout<Props> = ({
341339
return false;
342340
});
343341

344-
useEffect(() => {
345-
if (
346-
availableSections.length > 0 &&
347-
!availableSections.find(([key]) => key === activeSection)
348-
) {
349-
setActiveSection(availableSections[0][0]);
350-
}
351-
}, []);
342+
const currentSection = availableSections.find(([key]) => key === activeSection) ? currentSection : availableSections[0]?.[0] ?? "general";
352343

353344
const panelClass =
354345
"rounded-2xl bg-white shadow-[0_1px_3px_0_rgb(0,0,0,0.06),0_1px_2px_-1px_rgb(0,0,0,0.04)] dark:bg-zinc-900/70 dark:shadow-zinc-950/30";
355346

356347
const renderContent = () => {
357-
if (activeSection === "permissions") {
348+
if (currentSection === "permissions") {
358349
return (
359350
<div className={`${panelClass} p-5 sm:p-6`}>
360351
<Permissions
@@ -367,15 +358,15 @@ const Settings: pageWithLayout<Props> = ({
367358
);
368359
}
369360

370-
if (activeSection === "audit") {
361+
if (currentSection === "audit") {
371362
return (
372363
<div className={`${panelClass} p-5 sm:p-6`}>
373364
<All.AuditLogs />
374365
</div>
375366
);
376367
}
377368

378-
if (activeSection === "api") {
369+
if (currentSection === "api") {
379370
const apiComponents = [...SECTIONS.api.components];
380371
const apiKeyIndex = apiComponents.findIndex(({ key }) =>
381372
key.toLowerCase().includes("key"),
@@ -395,7 +386,7 @@ const Settings: pageWithLayout<Props> = ({
395386
);
396387
}
397388

398-
if (activeSection === "features") {
389+
if (currentSection === "features") {
399390
return (
400391
<div className={`${panelClass} overflow-hidden`}>
401392
<div className="divide-y divide-zinc-100 dark:divide-zinc-800">
@@ -410,8 +401,8 @@ const Settings: pageWithLayout<Props> = ({
410401
);
411402
}
412403

413-
const section = SECTIONS[activeSection as keyof typeof SECTIONS];
414-
const isServices = activeSection === "instance";
404+
const section = SECTIONS[currentSection as keyof typeof SECTIONS];
405+
const isServices = currentSection === "instance";
415406

416407
if (isServices) {
417408
return (
@@ -443,7 +434,7 @@ const Settings: pageWithLayout<Props> = ({
443434
} else {
444435
componentProps.isSidebarExpanded = isSidebarExpanded;
445436
componentProps.hasResetActivityOnly =
446-
activeSection === "activity" &&
437+
currentSection === "activity" &&
447438
!isAdmin &&
448439
!userPermissions.includes("workspace_customisation");
449440
}
@@ -483,13 +474,13 @@ const Settings: pageWithLayout<Props> = ({
483474
<nav className="space-y-0.5">
484475
{availableSections.map(([key, section]) => {
485476
const Icon = section.icon;
486-
const isActive = activeSection === key;
477+
const isActive = currentSection === key;
487478
return (
488479
<button
489480
key={key}
490481
onClick={() => {
491482
const encoded = encodeTab(key);
492-
setActiveSection(key);
483+
setcurrentSection(key);
493484
router.replace(
494485
{
495486
pathname: router.pathname,
@@ -517,11 +508,11 @@ const Settings: pageWithLayout<Props> = ({
517508
<div className="flex-1 min-w-0">
518509
<div className="mb-5">
519510
<h2 className="text-base font-semibold text-zinc-900 dark:text-zinc-100">
520-
{SECTIONS[activeSection as keyof typeof SECTIONS]?.name ||
511+
{SECTIONS[currentSection as keyof typeof SECTIONS]?.name ||
521512
"Settings"}
522513
</h2>
523514
<p className="text-sm text-zinc-400 dark:text-zinc-500 mt-0.5">
524-
{SECTIONS[activeSection as keyof typeof SECTIONS]
515+
{SECTIONS[currentSection as keyof typeof SECTIONS]
525516
?.description || "Manage your settings"}
526517
</p>
527518
</div>

0 commit comments

Comments
 (0)