Skip to content

Commit de00605

Browse files
committed
refactor: improve error handling
1 parent de8d224 commit de00605

File tree

6 files changed

+29
-18
lines changed

6 files changed

+29
-18
lines changed

messages/en.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@
332332
"update": "Update",
333333
"unregister": "Unregister",
334334
"signIn": "Sign in",
335+
"signInDescription": "Sign in to register for shifts",
335336
"registerSuccess": "Registered shift successfully",
336337
"updateSuccess": "Updated shift successfully",
337338
"unregisterSuccess": "Unregistered from shift successfully"
@@ -341,7 +342,8 @@
341342
"api": {
342343
"day": "Invalid day",
343344
"timeslot": "Invalid timeslot",
344-
"recurring": "Invalid value for recurring"
345+
"recurring": "Invalid value for recurring",
346+
"fetchShiftsFailed": "Failed to fetch shifts"
345347
}
346348
},
347349
"events": {

messages/no.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@
187187
"account": {
188188
"title": "Konto",
189189
"updateAccount": "Oppdater konto",
190-
"updateAccountFailed": "Failed to update account",
190+
"updateAccountFailed": "Kunne ikke oppdatere konto",
191191
"updateAccountSuccess": "Konto oppdatert",
192192
"email": {
193193
"label": "E-post",
@@ -332,6 +332,7 @@
332332
"update": "Oppdater",
333333
"unregister": "Avregistrer",
334334
"signIn": "Logg inn",
335+
"signInDescription": "Logg inn for å registrere vakt",
335336
"registerSuccess": "Vakt registrert",
336337
"updateSuccess": "Vakt oppdatert",
337338
"unregisterSuccess": "Vakt avregistrert"
@@ -341,7 +342,8 @@
341342
"api": {
342343
"day": "Ugyldig dag",
343344
"timeslot": "Ugyldig tidsrom",
344-
"recurring": "Ugyldig verdi for gjentagende"
345+
"recurring": "Ugyldig verdi for gjentagende",
346+
"fetchShiftsFailed": "Kunne ikke hente vakter"
345347
}
346348
},
347349
"events": {

src/components/shift-schedule/MemberList.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
import { SkillIcon } from '@/components/skills/SkillIcon';
2-
import type { Member } from '@/server/api/routers';
2+
import type { RouterOutputs } from '@/lib/api/client';
3+
import { useTranslations } from 'next-intl';
34

45
type MemberListProps = {
5-
t: {
6-
empty: string;
7-
};
8-
members: Member[];
6+
members: RouterOutputs['shiftSchedule']['fetchShifts'][number]['members'];
97
};
108

11-
function MemberList({ t, members }: MemberListProps) {
9+
function MemberList({ members }: MemberListProps) {
10+
const t = useTranslations('shiftSchedule.table.cell.dialog');
1211
return (
1312
<>
1413
{members.length === 0 ? (
15-
<p className='leading-tight'>{t.empty}</p>
14+
<p className='leading-tight'>{t('empty')}</p>
1615
) : (
1716
<div>
1817
{members?.map((member) => (

src/components/shift-schedule/RegisterShiftForm.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,12 @@ function RegisterShiftForm({
117117
</form.AppForm>
118118
</form>
119119
) : (
120-
<Link variant='default' size='default' href='/auth'>
120+
<Link
121+
variant='default'
122+
size='default'
123+
href='/auth'
124+
title={t('signInDescription')}
125+
>
121126
{t('signIn')}
122127
</Link>
123128
)}

src/components/shift-schedule/ScheduleCellDialog.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,7 @@ function ScheduleCellDialog({
4747
</ResponsiveDialogDescription>
4848
</ResponsiveDialogHeader>
4949
<div className='flex justify-between gap-8 px-1.5 pb-1.5'>
50-
<MemberList
51-
t={{
52-
empty: t('empty'),
53-
}}
54-
members={members}
55-
/>
50+
<MemberList members={members} />
5651
<RegisterShiftForm
5752
day={day}
5853
timeslot={timeslot}

src/server/api/routers/shiftSchedule.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
registerShiftSchema,
1212
unregisterShiftSchema,
1313
} from '@/validations/shiftSchedule/registerShiftSchema';
14+
import { TRPCError } from '@trpc/server';
1415
import { endOfWeek } from 'date-fns';
1516
import { and, eq, gte, isNull, or, sql } from 'drizzle-orm';
1617

@@ -46,7 +47,14 @@ const shiftScheduleRouter = createRouter({
4647
.leftJoin(userSkills, eq(users.id, userSkills.userId))
4748
.leftJoin(skills, eq(userSkills.skillId, skills.id))
4849
.where(or(isNull(shifts.endDate), gte(shifts.endDate, new Date())))
49-
.groupBy(shifts.day, shifts.timeslot, shifts.endDate, users.id);
50+
.groupBy(shifts.day, shifts.timeslot, shifts.endDate, users.id)
51+
.catch(() => {
52+
throw new TRPCError({
53+
code: 'INTERNAL_SERVER_ERROR',
54+
message: ctx.t('shiftSchedule.api.fetchShiftsFailed'),
55+
cause: { toast: 'error' },
56+
});
57+
});
5058

5159
const returnShifts: Shift[] = [];
5260
for (const day of days) {

0 commit comments

Comments
 (0)