Skip to content

Commit

Permalink
feat: onboarding session "Uploaded By" field 👋 (#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomas-salgado authored Jun 5, 2024
1 parent 59933e4 commit 63314bd
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
13 changes: 11 additions & 2 deletions apps/admin-dashboard/app/routes/_dashboard.onboarding-sessions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ async function listOnboardingSessions({
}: OnboardingSessionsSearchParams) {
const attendeesAggregation = sql<string>`
string_agg(
students.first_name || ' ' || last_name,
students.first_name || ' ' || students.last_name,
', '
ORDER BY
students.first_name,
Expand All @@ -83,13 +83,16 @@ async function listOnboardingSessions({
'onboardingSessions.id'
)
.leftJoin('students', 'students.id', 'onboardingSessionAttendees.studentId')
.leftJoin('admins', 'admins.id', 'onboardingSessions.uploadedById')
.select([
'onboardingSessions.date',
'onboardingSessions.group',
'onboardingSessions.id',
'admins.firstName as ambassadorFirstName',
'admins.lastName as ambassadorLastName',
attendeesAggregation,
])
.groupBy('onboardingSessions.id')
.groupBy(['onboardingSessions.id', 'admins.firstName', 'admins.lastName'])
.orderBy('onboardingSessions.date', 'desc')
.orderBy('onboardingSessions.group', 'desc')
.limit(limit)
Expand All @@ -100,6 +103,7 @@ async function listOnboardingSessions({
return {
...row,
date: dayjs(row.date).format('MM/DD/YY'),
ambassadorName: `${row.ambassadorFirstName} ${row.ambassadorLastName}`,
};
});

Expand Down Expand Up @@ -166,6 +170,11 @@ function OnboardingSessionsTable() {
render: (session) => session.attendees,
size: null,
},
{
displayName: 'Uploaded By',
render: (session) => session.ambassadorName,
size: null,
},
];

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
commitSession,
ensureUserAuthenticated,
toast,
user,
} from '@/shared/session.server';

export async function loader({ request }: LoaderFunctionArgs) {
Expand All @@ -38,6 +39,7 @@ const UploadOnboardingSessionInput = OnboardingSession.pick({
.trim()
.min(1, { message: 'Please select at least one attendee.' })
.transform((value) => value.split(',')),
uploadedById: z.string().trim().min(1),
});

type UploadOnboardingSessionInput = z.infer<
Expand All @@ -49,8 +51,12 @@ export async function action({ request }: ActionFunctionArgs) {
allowAmbassador: true,
});

const adminId = user(session);

const form = await request.formData();

form.set('uploadedById', adminId);

const { data, errors } = validateForm(
UploadOnboardingSessionInput,
Object.fromEntries(form)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { db } from '@/infrastructure/database';
type UploadOnboardingSessionInput = {
attendees: string[];
date: string;
uploadedById: string;
};

export async function uploadOnboardingSession(
Expand All @@ -21,6 +22,7 @@ export async function uploadOnboardingSession(
.values({
date: input.date,
id: onboardingSessionId,
uploadedById: input.uploadedById,
})
.execute();

Expand Down
17 changes: 17 additions & 0 deletions packages/db/src/migrations/20240605015405_ambassador_upload.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { type Kysely } from 'kysely';

export async function up(db: Kysely<any>) {
await db.schema
.alterTable('onboarding_sessions')
.addColumn('uploaded_by_id', 'text', (column) => {
return column.references('admins.id').onDelete('set null');
})
.execute();
}

export async function down(db: Kysely<any>) {
await db.schema
.alterTable('onboarding_sessions')
.dropColumn('uploaded_by_id')
.execute();
}

0 comments on commit 63314bd

Please sign in to comment.