197 lines
8 KiB
Vue
197 lines
8 KiB
Vue
<template>
|
|
<div class="w-full md:max-w-md">
|
|
<div class="flex flex-col items-center">
|
|
<p class="text-xl font-medium">Mitglied-Qualifikation bearbeiten</p>
|
|
</div>
|
|
<br />
|
|
<Spinner v-if="loading == 'loading'" class="mx-auto" />
|
|
<p v-else-if="loading == 'failed'" @click="fetchItem" class="cursor-pointer">↺ laden fehlgeschlagen</p>
|
|
<form v-else-if="memberQualification != null" class="flex flex-col gap-4 py-2" @submit.prevent="triggerCreate">
|
|
<div>
|
|
<Listbox v-model="memberQualification.qualificationId" name="qualification">
|
|
<ListboxLabel>Qualifikation</ListboxLabel>
|
|
<div class="relative mt-1">
|
|
<ListboxButton
|
|
class="rounded-md shadow-sm relative block w-full px-3 py-2 border border-gray-300 focus:border-primary placeholder-gray-500 text-gray-900 rounded-b-md focus:outline-none focus:ring-0 focus:z-10 sm:text-sm resize-none"
|
|
>
|
|
<span class="block truncate w-full text-start">
|
|
{{
|
|
qualifications.length != 0 ? (selectedQualification ?? "bitte auswählen") : "keine Auswahl vorhanden"
|
|
}}</span
|
|
>
|
|
<span class="pointer-events-none absolute inset-y-0 right-0 flex items-center pr-2">
|
|
<ChevronUpDownIcon class="h-5 w-5 text-gray-400" aria-hidden="true" />
|
|
</span>
|
|
</ListboxButton>
|
|
|
|
<transition
|
|
leave-active-class="transition duration-100 ease-in"
|
|
leave-from-class="opacity-100"
|
|
leave-to-class="opacity-0"
|
|
>
|
|
<ListboxOptions
|
|
class="absolute mt-1 max-h-60 z-20 w-full overflow-auto rounded-md bg-white py-1 text-base shadow-lg ring-1 ring-black/5 focus:outline-none sm:text-sm h-32 overflow-y-auto"
|
|
>
|
|
<ListboxOption v-if="qualifications.length == 0" disabled as="template">
|
|
<li :class="['relative cursor-default select-none py-2 pl-10 pr-4']">
|
|
<span :class="['font-normal', 'block truncate']">keine Auswahl vorhanden</span>
|
|
</li>
|
|
</ListboxOption>
|
|
<ListboxOption
|
|
v-slot="{ active, selected }"
|
|
v-for="qualification in qualifications"
|
|
:key="qualification.id"
|
|
:value="qualification.id"
|
|
as="template"
|
|
>
|
|
<li
|
|
:class="[
|
|
active ? 'bg-red-200 text-amber-900' : 'text-gray-900',
|
|
'relative cursor-default select-none py-2 pl-10 pr-4',
|
|
]"
|
|
>
|
|
<span :class="[selected ? 'font-medium' : 'font-normal', 'block truncate']">{{
|
|
qualification.qualification
|
|
}}</span>
|
|
<span v-if="selected" class="absolute inset-y-0 left-0 flex items-center pl-3 text-primary">
|
|
<CheckIcon class="h-5 w-5" aria-hidden="true" />
|
|
</span>
|
|
</li>
|
|
</ListboxOption>
|
|
</ListboxOptions>
|
|
</transition>
|
|
</div>
|
|
</Listbox>
|
|
</div>
|
|
<div>
|
|
<label for="start">Startdatum</label>
|
|
<input type="date" id="start" required v-model="memberQualification.start" />
|
|
</div>
|
|
<div>
|
|
<label for="note">Notiz (optional)</label>
|
|
<input type="text" id="note" v-model="memberQualification.note" />
|
|
</div>
|
|
<div>
|
|
<label for="end">Enddatum (optional)</label>
|
|
<input type="date" id="end" v-model="memberQualification.end" />
|
|
</div>
|
|
<div>
|
|
<label for="terminationReason">beendet, weil (optional)</label>
|
|
<input type="text" id="terminationReason" v-model="memberQualification.terminationReason" />
|
|
</div>
|
|
<div class="flex flex-row gap-2">
|
|
<button primary-outline type="reset" :disabled="canSaveOrReset" @click="resetForm">verwerfen</button>
|
|
<button primary type="submit" :disabled="status == 'loading' || canSaveOrReset">speichern</button>
|
|
<Spinner v-if="status == 'loading'" class="my-auto" />
|
|
<SuccessCheckmark v-else-if="status?.status == 'success'" />
|
|
<FailureXMark v-else-if="status?.status == 'failed'" />
|
|
</div>
|
|
</form>
|
|
|
|
<div class="flex flex-row justify-end">
|
|
<div class="flex flex-row gap-4 py-2">
|
|
<button primary-outline @click="closeModal" :disabled="status == 'loading' || status?.status == 'success'">
|
|
schließen
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { defineComponent } from "vue";
|
|
import { mapState, mapActions } from "pinia";
|
|
import { useModalStore } from "@/stores/modal";
|
|
import Spinner from "@/components/Spinner.vue";
|
|
import SuccessCheckmark from "@/components/SuccessCheckmark.vue";
|
|
import FailureXMark from "@/components/FailureXMark.vue";
|
|
import { Listbox, ListboxButton, ListboxOptions, ListboxOption, ListboxLabel } from "@headlessui/vue";
|
|
import { CheckIcon, ChevronUpDownIcon } from "@heroicons/vue/20/solid";
|
|
import { useQualificationStore } from "@/stores/admin/configuration/qualification";
|
|
import type {
|
|
CreateMemberQualificationViewModel,
|
|
MemberQualificationViewModel,
|
|
UpdateMemberQualificationViewModel,
|
|
} from "@/viewmodels/admin/club/member/memberQualification.models";
|
|
import { useMemberQualificationStore } from "@/stores/admin/club/member/memberQualification";
|
|
import isEqual from "lodash.isequal";
|
|
import cloneDeep from "lodash.clonedeep";
|
|
</script>
|
|
|
|
<script lang="ts">
|
|
export default defineComponent({
|
|
data() {
|
|
return {
|
|
loading: "loading" as "loading" | "fetched" | "failed",
|
|
status: null as null | "loading" | { status: "success" | "failed"; reason?: string },
|
|
origin: null as null | MemberQualificationViewModel,
|
|
memberQualification: null as null | MemberQualificationViewModel,
|
|
timeout: undefined as any,
|
|
};
|
|
},
|
|
computed: {
|
|
...mapState(useQualificationStore, ["qualifications"]),
|
|
...mapState(useModalStore, ["data"]),
|
|
canSaveOrReset(): boolean {
|
|
return isEqual(this.origin, this.memberQualification);
|
|
},
|
|
selectedQualification() {
|
|
return this.qualifications.find((ms) => ms.id == this.memberQualification?.qualificationId)?.qualification;
|
|
},
|
|
},
|
|
mounted() {
|
|
this.fetchQualifications();
|
|
this.fetchItem();
|
|
},
|
|
beforeUnmount() {
|
|
try {
|
|
clearTimeout(this.timeout);
|
|
} catch (error) {}
|
|
},
|
|
methods: {
|
|
...mapActions(useModalStore, ["closeModal"]),
|
|
...mapActions(useMemberQualificationStore, ["updateMemberQualification", "fetchMemberQualificationById"]),
|
|
...mapActions(useQualificationStore, ["fetchQualifications"]),
|
|
resetForm() {
|
|
this.memberQualification = cloneDeep(this.origin);
|
|
},
|
|
fetchItem() {
|
|
this.fetchMemberQualificationById(this.data)
|
|
.then((result) => {
|
|
this.memberQualification = result.data;
|
|
this.origin = cloneDeep(result.data);
|
|
this.loading = "fetched";
|
|
})
|
|
.catch((err) => {
|
|
this.loading = "failed";
|
|
});
|
|
},
|
|
triggerCreate(e: any) {
|
|
if (this.memberQualification == null) return;
|
|
let formData = e.target.elements;
|
|
let updateMemberQualification: UpdateMemberQualificationViewModel = {
|
|
id: this.memberQualification.id,
|
|
start: formData.start.value,
|
|
note: formData.note.value,
|
|
end: formData.end.value,
|
|
terminationReason: formData.terminationReason.value,
|
|
qualificationId: this.memberQualification.qualificationId,
|
|
};
|
|
this.status = "loading";
|
|
this.updateMemberQualification(updateMemberQualification)
|
|
.then(() => {
|
|
this.fetchItem();
|
|
this.status = { status: "success" };
|
|
})
|
|
.catch((err) => {
|
|
this.status = { status: "failed" };
|
|
})
|
|
.finally(() => {
|
|
this.timeout = setTimeout(() => {
|
|
this.status = null;
|
|
}, 2000);
|
|
});
|
|
},
|
|
},
|
|
});
|
|
</script>
|