|
|
@@ -110,6 +110,7 @@
|
|
|
icon="mdi-trash-can-outline"
|
|
|
color="grey-5"
|
|
|
size="sm"
|
|
|
+ :loading="deletingId === holiday.id"
|
|
|
@click="removeHoliday(holiday)"
|
|
|
/>
|
|
|
</q-item-section>
|
|
|
@@ -168,6 +169,7 @@
|
|
|
label="SALVAR"
|
|
|
no-caps
|
|
|
:disable="!newDescription.trim()"
|
|
|
+ :loading="saving"
|
|
|
@click="saveNewRecord"
|
|
|
/>
|
|
|
</q-card-actions>
|
|
|
@@ -178,14 +180,16 @@
|
|
|
|
|
|
<script setup>
|
|
|
import { ref, computed } from "vue";
|
|
|
-import { useDialogPluginComponent } from "quasar";
|
|
|
+import { useDialogPluginComponent, useQuasar } from "quasar";
|
|
|
import DefaultDialogHeader from "src/components/defaults/DefaultDialogHeader.vue";
|
|
|
import DefaultInput from "src/components/defaults/DefaultInput.vue";
|
|
|
import DefaultSelect from "src/components/defaults/DefaultSelect.vue";
|
|
|
+import { createBaseHoliday, deleteBaseHoliday } from "src/api/holiday";
|
|
|
|
|
|
defineEmits([...useDialogPluginComponent.emits]);
|
|
|
|
|
|
const { dialogRef, onDialogHide, onDialogOK } = useDialogPluginComponent();
|
|
|
+const $q = useQuasar();
|
|
|
|
|
|
const now = new Date();
|
|
|
const currentMonth = ref(now.getMonth() + 1);
|
|
|
@@ -195,6 +199,8 @@ const view = ref("calendar");
|
|
|
const selectedDay = ref(null);
|
|
|
const newDescription = ref("");
|
|
|
const newType = ref("feriado");
|
|
|
+const saving = ref(false);
|
|
|
+const deletingId = ref(null);
|
|
|
|
|
|
const props = defineProps({
|
|
|
initialHolidays: {
|
|
|
@@ -203,9 +209,6 @@ const props = defineProps({
|
|
|
},
|
|
|
});
|
|
|
|
|
|
-let nextId = props.initialHolidays.length
|
|
|
- ? Math.max(...props.initialHolidays.map((h) => h.id)) + 1
|
|
|
- : 1;
|
|
|
const holidays = ref([...props.initialHolidays]);
|
|
|
|
|
|
const weekDays = ["Dom", "Seg", "Ter", "Qua", "Qui", "Sex", "Sáb"];
|
|
|
@@ -298,25 +301,49 @@ function cancelNewRecord() {
|
|
|
selectedDay.value = null;
|
|
|
}
|
|
|
|
|
|
-function saveNewRecord() {
|
|
|
+async function saveNewRecord() {
|
|
|
const desc = newDescription.value.trim();
|
|
|
if (!desc || selectedDay.value === null) return;
|
|
|
|
|
|
- holidays.value.push({
|
|
|
- id: nextId++,
|
|
|
- day: selectedDay.value,
|
|
|
- month: currentMonth.value,
|
|
|
- year: currentYear.value,
|
|
|
- description: desc,
|
|
|
- type: newType.value,
|
|
|
- });
|
|
|
+ const mm = String(currentMonth.value).padStart(2, "0");
|
|
|
+ const dd = String(selectedDay.value).padStart(2, "0");
|
|
|
|
|
|
- view.value = "calendar";
|
|
|
- selectedDay.value = null;
|
|
|
+ saving.value = true;
|
|
|
+ try {
|
|
|
+ const created = await createBaseHoliday({
|
|
|
+ description: desc,
|
|
|
+ holiday_date: `${currentYear.value}-${mm}-${dd}`,
|
|
|
+ type: newType.value,
|
|
|
+ });
|
|
|
+
|
|
|
+ holidays.value.push({
|
|
|
+ id: created.id,
|
|
|
+ day: selectedDay.value,
|
|
|
+ month: currentMonth.value,
|
|
|
+ year: currentYear.value,
|
|
|
+ description: created.description,
|
|
|
+ type: created.type,
|
|
|
+ });
|
|
|
+
|
|
|
+ view.value = "calendar";
|
|
|
+ selectedDay.value = null;
|
|
|
+ } catch {
|
|
|
+ $q.notify({ type: "negative", message: "Erro ao salvar feriado." });
|
|
|
+ } finally {
|
|
|
+ saving.value = false;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-function removeHoliday(holiday) {
|
|
|
- holidays.value = holidays.value.filter((h) => h.id !== holiday.id);
|
|
|
+async function removeHoliday(holiday) {
|
|
|
+ deletingId.value = holiday.id;
|
|
|
+ try {
|
|
|
+ await deleteBaseHoliday(holiday.id);
|
|
|
+ holidays.value = holidays.value.filter((h) => h.id !== holiday.id);
|
|
|
+ } catch {
|
|
|
+ $q.notify({ type: "negative", message: "Erro ao remover feriado." });
|
|
|
+ } finally {
|
|
|
+ deletingId.value = null;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
function onClose() {
|