homebox/frontend/components/Label/CreateModal.vue

68 lines
1.4 KiB
Vue
Raw Normal View History

2022-09-02 01:52:40 +00:00
<template>
<BaseModal v-model="modal">
<template #title> Create Label </template>
<form @submit.prevent="create">
<FormTextField
ref="locationNameRef"
v-model="form.name"
:trigger-focus="focused"
2022-09-02 01:52:40 +00:00
:autofocus="true"
label="Label Name"
/>
<FormTextArea v-model="form.description" label="Label Description" />
2022-09-02 01:52:40 +00:00
<div class="modal-action">
<BaseButton type="submit" :loading="loading"> Create </BaseButton>
</div>
</form>
</BaseModal>
</template>
<script setup lang="ts">
const props = defineProps({
modelValue: {
type: Boolean,
required: true,
},
});
const modal = useVModel(props, "modelValue");
2022-09-02 01:52:40 +00:00
const loading = ref(false);
const focused = ref(false);
const form = reactive({
name: "",
description: "",
color: "", // Future!
2022-09-02 01:52:40 +00:00
});
function reset() {
form.name = "";
form.description = "";
form.color = "";
2022-09-02 01:52:40 +00:00
focused.value = false;
modal.value = false;
loading.value = false;
}
whenever(
() => modal.value,
() => {
focused.value = true;
}
);
const api = useUserApi();
const toast = useNotifier();
async function create() {
const { error, data } = await api.labels.create(form);
2022-09-02 01:52:40 +00:00
if (error) {
toast.error("Couldn't create label");
return;
}
toast.success("Label created");
2022-09-02 01:52:40 +00:00
reset();
navigateTo(`/label/${data.id}`);
2022-09-02 01:52:40 +00:00
}
</script>