2022-09-02 01:52:40 +00:00
|
|
|
<template>
|
|
|
|
<BaseModal v-model="modal">
|
|
|
|
<template #title> Create Label </template>
|
2023-08-02 21:00:57 +00:00
|
|
|
<form @submit.prevent="create()">
|
2022-09-02 01:52:40 +00:00
|
|
|
<FormTextField
|
|
|
|
ref="locationNameRef"
|
2022-09-09 22:46:53 +00:00
|
|
|
v-model="form.name"
|
|
|
|
:trigger-focus="focused"
|
2022-09-02 01:52:40 +00:00
|
|
|
:autofocus="true"
|
|
|
|
label="Label Name"
|
|
|
|
/>
|
2022-09-25 22:33:13 +00:00
|
|
|
<FormTextArea v-model="form.description" label="Label Description" />
|
2022-09-02 01:52:40 +00:00
|
|
|
<div class="modal-action">
|
2023-07-31 17:53:26 +00:00
|
|
|
<div class="flex justify-center">
|
2023-08-02 21:00:57 +00:00
|
|
|
<BaseButton class="rounded-r-none" :loading="loading" type="submit"> Create </BaseButton>
|
2023-07-31 17:53:26 +00:00
|
|
|
<div class="dropdown dropdown-top">
|
|
|
|
<label tabindex="0" class="btn rounded-l-none rounded-r-xl">
|
2024-03-01 01:20:18 +00:00
|
|
|
<MdiChevronDown class="h-5 w-5" />
|
2023-07-31 17:53:26 +00:00
|
|
|
</label>
|
2023-08-31 17:07:45 +00:00
|
|
|
<ul tabindex="0" class="dropdown-content menu p-2 shadow bg-base-100 rounded-box w-64 right-0">
|
2023-07-31 17:53:26 +00:00
|
|
|
<li>
|
2023-08-02 21:00:57 +00:00
|
|
|
<button type="button" @click="create(false)">Create and Add Another</button>
|
2023-07-31 17:53:26 +00:00
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-09-02 01:52:40 +00:00
|
|
|
</div>
|
2023-08-02 21:00:57 +00:00
|
|
|
</form>
|
2023-07-31 17:53:26 +00:00
|
|
|
<p class="text-sm text-center mt-4">
|
2023-08-02 21:00:57 +00:00
|
|
|
use <kbd class="kbd kbd-xs">Shift</kbd> + <kbd class="kbd kbd-xs"> Enter </kbd> to create and add another
|
2023-07-31 17:53:26 +00:00
|
|
|
</p>
|
2022-09-02 01:52:40 +00:00
|
|
|
</BaseModal>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
2024-03-01 01:20:18 +00:00
|
|
|
import MdiChevronDown from "~icons/mdi/chevron-down";
|
2022-09-02 01:52:40 +00:00
|
|
|
const props = defineProps({
|
|
|
|
modelValue: {
|
|
|
|
type: Boolean,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2022-09-09 22:46:53 +00:00
|
|
|
const modal = useVModel(props, "modelValue");
|
2022-09-02 01:52:40 +00:00
|
|
|
const loading = ref(false);
|
|
|
|
const focused = ref(false);
|
|
|
|
const form = reactive({
|
2022-09-09 22:46:53 +00:00
|
|
|
name: "",
|
|
|
|
description: "",
|
|
|
|
color: "", // Future!
|
2022-09-02 01:52:40 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
function reset() {
|
2022-09-09 22:46:53 +00:00
|
|
|
form.name = "";
|
|
|
|
form.description = "";
|
|
|
|
form.color = "";
|
2022-09-02 01:52:40 +00:00
|
|
|
focused.value = false;
|
|
|
|
loading.value = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
whenever(
|
|
|
|
() => modal.value,
|
|
|
|
() => {
|
|
|
|
focused.value = true;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
const api = useUserApi();
|
|
|
|
const toast = useNotifier();
|
|
|
|
|
2023-08-02 21:00:57 +00:00
|
|
|
const { shift } = useMagicKeys();
|
|
|
|
|
|
|
|
async function create(close = true) {
|
|
|
|
if (shift.value) {
|
|
|
|
close = false;
|
|
|
|
}
|
|
|
|
|
2022-11-01 03:07:01 +00:00
|
|
|
const { error, data } = await api.labels.create(form);
|
2022-09-02 01:52:40 +00:00
|
|
|
if (error) {
|
|
|
|
toast.error("Couldn't create label");
|
2023-10-06 21:22:16 +00:00
|
|
|
loading.value = false;
|
2022-09-02 01:52:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-09-09 22:46:53 +00:00
|
|
|
toast.success("Label created");
|
2022-09-02 01:52:40 +00:00
|
|
|
reset();
|
2023-07-31 17:53:26 +00:00
|
|
|
|
|
|
|
if (close) {
|
|
|
|
modal.value = false;
|
|
|
|
navigateTo(`/label/${data.id}`);
|
|
|
|
}
|
|
|
|
}
|
2022-09-02 01:52:40 +00:00
|
|
|
</script>
|