Skip to content

Commit 1388475

Browse files
authored
Merge pull request #1224 from david-roper/make-session-noticeable
Make session noticeable
2 parents 6dcaae3 + 9cfbfaa commit 1388475

File tree

5 files changed

+63
-14
lines changed

5 files changed

+63
-14
lines changed

apps/api/src/instrument-records/instrument-records.service.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ export class InstrumentRecordsService {
139139
select: {
140140
date: true,
141141
id: true,
142-
type: true
142+
type: true,
143+
user: true
143144
}
144145
},
145146
subject: true
@@ -184,6 +185,7 @@ export class InstrumentRecordsService {
184185
subjectId: removeSubjectIdScope(record.subject.id),
185186
subjectSex: record.subject.sex,
186187
timestamp: record.date.toISOString(),
188+
userId: record.session.user?.username ?? 'N/A',
187189
value: measureValue
188190
});
189191
}
@@ -207,6 +209,7 @@ export class InstrumentRecordsService {
207209
subjectId: removeSubjectIdScope(record.subject.id),
208210
subjectSex: record.subject.sex,
209211
timestamp: record.date.toISOString(),
212+
userId: record.session.user?.username ?? 'N/A',
210213
value: arrayEntry.measureValue
211214
});
212215
});

apps/api/src/sessions/sessions.controller.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { RouteAccess } from '@douglasneuroinformatics/libnest';
2-
import { Body, Controller, Post } from '@nestjs/common';
1+
import { CurrentUser, RouteAccess } from '@douglasneuroinformatics/libnest';
2+
import type { AppAbility } from '@douglasneuroinformatics/libnest';
3+
import { Body, Controller, Get, Param, Post } from '@nestjs/common';
34
import { ApiOperation } from '@nestjs/swagger';
45
import type { Session } from '@prisma/client';
56

@@ -16,4 +17,11 @@ export class SessionsController {
1617
create(@Body() data: CreateSessionDto): Promise<Session> {
1718
return this.sessionsService.create(data);
1819
}
20+
21+
@ApiOperation({ description: 'Find Session by ID' })
22+
@Get(':id')
23+
@RouteAccess({ action: 'read', subject: 'Session' })
24+
findByID(@Param('id') id: string, @CurrentUser('ability') ability: AppAbility): Promise<Session> {
25+
return this.sessionsService.findById(id, { ability });
26+
}
1927
}

apps/web/src/components/Navbar/Navbar.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export const Navbar = () => {
1818
const navItems = useNavItems();
1919
const { t } = useTranslation('layout');
2020
const navigate = useNavigate();
21+
const endSession = useAppStore((store) => store.endSession);
2122

2223
// This is to prevent ugly styling when resizing the viewport
2324
const isDesktop = useIsDesktop();
@@ -83,6 +84,10 @@ export const Navbar = () => {
8384
isActive={false}
8485
label={t('navLinks.endSession')}
8586
url="#"
87+
onClick={() => {
88+
endSession();
89+
void navigate({ to: '/session/start-session' });
90+
}}
8691
/>
8792
)}
8893
</div>

apps/web/src/routes/_app/session/start-session.tsx

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import React, { useEffect, useState } from 'react';
22

3-
import { Heading } from '@douglasneuroinformatics/libui/components';
3+
import { Card, Heading } from '@douglasneuroinformatics/libui/components';
44
import { useTranslation } from '@douglasneuroinformatics/libui/hooks';
55
import type { FormTypes } from '@opendatacapture/runtime-core';
66
import { createFileRoute, useLocation } from '@tanstack/react-router';
7+
import { CheckCircle } from 'lucide-react';
8+
import { AnimatePresence, motion } from 'motion/react';
79

810
import { PageHeader } from '@/components/PageHeader';
911
import { StartSessionForm } from '@/components/StartSessionForm';
@@ -41,16 +43,45 @@ const RouteComponent = () => {
4143
{t('startSession')}
4244
</Heading>
4345
</PageHeader>
44-
<StartSessionForm
45-
currentGroup={currentGroup}
46-
initialValues={initialValues}
47-
readOnly={currentSession !== null || createSessionMutation.isPending}
48-
username={currentUser?.username}
49-
onSubmit={async (formData) => {
50-
const session = await createSessionMutation.mutateAsync(formData);
51-
startSession({ ...session, type: formData.type });
52-
}}
53-
/>
46+
{currentSession === null && (
47+
<StartSessionForm
48+
currentGroup={currentGroup}
49+
initialValues={initialValues}
50+
readOnly={currentSession !== null || createSessionMutation.isPending}
51+
username={currentUser?.username}
52+
onSubmit={async (formData) => {
53+
const session = await createSessionMutation.mutateAsync(formData);
54+
startSession({ ...session, type: formData.type });
55+
}}
56+
/>
57+
)}
58+
<AnimatePresence>
59+
{currentSession !== null && (
60+
<motion.div
61+
animate={{ opacity: 1, scale: 1 }}
62+
className="flex grow"
63+
exit={{ opacity: 0, scale: 0 }}
64+
initial={{ opacity: 0, scale: 0 }}
65+
key="modal"
66+
>
67+
<div className="flex grow items-center justify-center">
68+
{currentSession !== null && (
69+
<Card className="mx-auto block max-w-3xl border p-12 text-green-600 opacity-70 dark:text-green-300">
70+
<div className="flex flex-col items-center justify-center gap-y-10">
71+
<CheckCircle className="!size-20" />
72+
<p className="max-w-2xl text-center text-lg font-medium">
73+
{t({
74+
en: 'The current session must be ended before starting the form again.',
75+
fr: 'La session en cours doit être terminée avant de recommencer le formulaire.'
76+
})}
77+
</p>
78+
</div>
79+
</Card>
80+
)}
81+
</div>
82+
</motion.div>
83+
)}
84+
</AnimatePresence>
5485
</React.Fragment>
5586
);
5687
};

packages/schemas/src/instrument-records/instrument-records.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export const $InstrumentRecord = $BaseModel.extend({
3939
date: z.coerce.date(),
4040
groupId: z.string().nullish(),
4141
instrumentId: z.string(),
42+
sessionId: z.string(),
4243
subjectId: z.string()
4344
});
4445

@@ -56,6 +57,7 @@ export type InstrumentRecordsExport = {
5657
subjectId: string;
5758
subjectSex: null | string;
5859
timestamp: string;
60+
userId: string;
5961
value: InstrumentMeasureValue;
6062
}[];
6163

0 commit comments

Comments
 (0)