Skip to content

Commit

Permalink
feat: add shift assignment creation
Browse files Browse the repository at this point in the history
  • Loading branch information
krantheman committed May 8, 2024
1 parent ca35978 commit 533837c
Showing 1 changed file with 36 additions and 10 deletions.
46 changes: 36 additions & 10 deletions roster/src/components/ShiftAssignmentDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<template #body-content>
<div class="grid grid-cols-2 gap-6">
<Autocomplete
:type="'text'"
type="text"
label="Employee"
v-model="form.employee"
:class="!!props.shiftAssignmentName && 'pointer-events-none'"
Expand All @@ -22,11 +22,12 @@
v-model="form.start_date"
:disabled="!!props.shiftAssignmentName"
/>
<FormControl
<Autocomplete
type="text"
label="Shift Type"
label="Employee"
v-model="form.shift_type"
:disabled="!!props.shiftAssignmentName"
:class="!!props.shiftAssignmentName && 'pointer-events-none'"
:options="shiftTypes.data"
/>
<FormControl id="end_date" type="date" label="End Date" v-model="form.end_date" />
<FormControl
Expand Down Expand Up @@ -63,6 +64,7 @@ import {
FormControl,
createDocumentResource,
createResource,
createListResource,
} from "frappe-ui";
const props = defineProps({
Expand Down Expand Up @@ -151,15 +153,16 @@ watch(
},
);
const updateShiftAssigment = async () => {
await shiftAssignment.value.setValue.submit({ status: form.status, end_date: form.end_date });
emit("fetchShifts");
emit("closeDialog");
const updateShiftAssigment = () => {
shiftAssignment.value.setValue.submit({ status: form.status, end_date: form.end_date });
};
const createShiftAssigment = () => {
emit("fetchShifts");
emit("closeDialog");
shiftAssignments.insert.submit({
...form,
employee: form.employee.value,
shift_type: form.shift_type.value,
});
};
// RESOURCES
Expand All @@ -173,6 +176,12 @@ const getShiftAssignment = (name) =>
form[key] = data[key];
});
},
setValue: {
onSuccess() {
emit("fetchShifts");
emit("closeDialog");
},
},
});
const employee = createResource({
Expand All @@ -190,4 +199,21 @@ const employee = createResource({
form.department = data.department;
},
});
const shiftTypes = createListResource({
doctype: "Shift Type",
fields: ["name"],
transform: (data) => data.map((shiftType) => shiftType.name),
auto: true,
});
const shiftAssignments = createListResource({
doctype: "Shift Assignment",
insert: {
onSuccess() {
emit("fetchShifts");
emit("closeDialog");
},
},
});
</script>

0 comments on commit 533837c

Please sign in to comment.