Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 25 additions & 18 deletions apps/admin-dashboard/app/routes/_dashboard.students.remove.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
validateForm,
} from '@oyster/ui';
import { Callout } from '@oyster/ui/callout';
import { splitArray } from '@oyster/utils';

import { Route } from '@/shared/constants';
import {
Expand Down Expand Up @@ -66,23 +67,31 @@ export async function action({ request }: ActionFunctionArgs) {
}

async function removeMembers(ids: string[]): Promise<number> {
const students = await db
.deleteFrom('students')
.where('id', 'in', ids)
.returning(['airtableId', 'email', 'firstName', 'slackId'])
.execute();

for (const student of students) {
job('student.removed', {
airtableId: student.airtableId as string,
email: student.email,
firstName: student.firstName,
sendViolationEmail: false,
slackId: student.slackId,
});
const batches = splitArray(ids, 10);

let count = 0;

for (const batch of batches) {
const students = await db
.deleteFrom('students')
.where('id', 'in', batch)
.returning(['airtableId', 'email', 'firstName', 'slackId'])
.execute();

for (const student of students) {
job('student.removed', {
airtableId: student.airtableId as string,
email: student.email,
firstName: student.firstName,
sendViolationEmail: false,
slackId: student.slackId,
});
}

count += students.length;
}

return students.length;
return count;
}

export default function RemoveMembersPage() {
Expand Down Expand Up @@ -126,9 +135,7 @@ export default function RemoveMembersPage() {
</Field>

<Button.Group>
<Button color="error" type="submit">
Remove
</Button>
<Button.Submit color="error">Remove</Button.Submit>
</Button.Group>
</Form>
</Modal>
Expand Down