Skip to content

Commit

Permalink
New All
Browse files Browse the repository at this point in the history
  • Loading branch information
c0repwn3r committed Feb 29, 2024
1 parent 7078d2c commit a64e193
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hq",
"version": "1.3.4",
"version": "1.4.0",
"private": true,
"scripts": {
"dev": "vite dev",
Expand Down
31 changes: 31 additions & 0 deletions src/routes/admin/division_staff/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,37 @@ export const actions: Actions = {
form,
};
},
createAll: async (event) => {
let form = await superValidate(event, formSchema);

if (!form.valid) {
return fail(400, { form });
}

let { user } = await loadUserData(event.cookies, null);
if (!user.isSiteAdmin) {
return fail(400, { form });
}

let facilities = await prisma.facility.findMany();

for (let f of facilities) {
if (f.dotnetType === 'Subdivision') {
await prisma.userFacilityAssignment.create({
data: {
id: ulid(),
userId: form.data.cid.toString(),
facilityId: f.id,
assignmentType: "DivisionalStaff",
},
});
}
}

return {
form,
};
},
delete: async (event) => {
let { user } = await loadUserData(event.cookies, null);
if (!user.isSiteAdmin) {
Expand Down
51 changes: 49 additions & 2 deletions src/routes/admin/division_staff/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import * as Form from "$lib/components/ui/form";
import { Plus } from "lucide-svelte";
import { Button } from "$lib/components/ui/button";
import { formSchema, type FormSchema } from "./schema";
import { formSchema, type FormSchema, formSchema2, type FormSchema2 } from "./schema";
import type { SuperValidated } from "sveltekit-superforms";
import type { PageData } from "./$types";
import { toast } from "svelte-sonner";
Expand Down Expand Up @@ -49,6 +49,7 @@
let createDialogOpen = false;
export let form: SuperValidated<FormSchema>;
export let form2: SuperValidated<FormSchema2>;
let options = {
onUpdated: ({ form }) => {
Expand All @@ -58,6 +59,15 @@
}
},
};
let createDialogOpen2 = false;
let options2 = {
onUpdated: ({ form }) => {
if (form.valid) {
createDialogOpen2 = false;
toast.success("User assignments updated!");
}
},
};
</script>

<div class="flex items-center justify-between">
Expand All @@ -69,7 +79,14 @@
createDialogOpen = true;
}}>
<Plus class="mr-2 w-4 h-4" />
Create
New
</Button>
<Button
on:click={() => {
createDialogOpen2 = true;
}}>
<Plus class="mr-2 w-4 h-4" />
New All
</Button>
</div>

Expand Down Expand Up @@ -142,3 +159,33 @@
</div>
</Dialog.Content>
</Dialog.Root>

<Dialog.Root bind:open={createDialogOpen2}>
<Dialog.Content class="sm:max-w-[425px]">
<Dialog.Header>
<Dialog.Title>New Divisional Staff Assignment</Dialog.Title>
</Dialog.Header>

<div class="space-y-2">
<Form.Root
action="?/createAll"
method="POST"
form={form2}
schema={formSchema2}
options={options2}
let:config>
<Form.Field {config} name="cid">
<Form.Item>
<Form.Label>User CID</Form.Label>
<Form.Input />
<Form.Validation />
</Form.Item>
</Form.Field>
<Form.Button class="mt-2 w-100">
<Plus class="mr-2 w-4 h-4" />
New All
</Form.Button>
</Form.Root>
</div>
</Dialog.Content>
</Dialog.Root>
5 changes: 5 additions & 0 deletions src/routes/admin/division_staff/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@ export const formSchema = z.object({
facilityId: z.string(),
});

export const formSchema2 = z.object({
cid: z.string()
})

export type FormSchema = typeof formSchema;
export type FormSchema2 = typeof formSchema2;

0 comments on commit a64e193

Please sign in to comment.