mirror of
https://github.com/hay-kot/homebox.git
synced 2024-11-16 21:58:40 +00:00
3d295b5132
* location tree API * test fixes * initial tree location elements * locations tree page * update meta-data * code-gen * store item display preferences * introduce basic table/card view elements * codegen * set parent location during location creation * add item support for tree query * refactor tree view * wip: location selector improvements * type gen * rename items -> search * remove various log statements * fix markdown rendering for description * update location selectors * fix tests * fix currency tests * formatting
77 lines
1.7 KiB
Vue
77 lines
1.7 KiB
Vue
<template>
|
|
<BaseModal v-model="modal">
|
|
<template #title> Create Location </template>
|
|
<form @submit.prevent="create">
|
|
<FormTextField
|
|
ref="locationNameRef"
|
|
v-model="form.name"
|
|
:trigger-focus="focused"
|
|
:autofocus="true"
|
|
label="Location Name"
|
|
/>
|
|
<FormTextArea v-model="form.description" label="Location Description" />
|
|
<LocationSelector v-model="form.parent" />
|
|
<div class="modal-action">
|
|
<BaseButton type="submit" :loading="loading"> Create </BaseButton>
|
|
</div>
|
|
</form>
|
|
</BaseModal>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { LocationSummary } from "~~/lib/api/types/data-contracts";
|
|
const props = defineProps({
|
|
modelValue: {
|
|
type: Boolean,
|
|
required: true,
|
|
},
|
|
});
|
|
|
|
const modal = useVModel(props, "modelValue");
|
|
const loading = ref(false);
|
|
const focused = ref(false);
|
|
const form = reactive({
|
|
name: "",
|
|
description: "",
|
|
parent: null as LocationSummary | null,
|
|
});
|
|
|
|
whenever(
|
|
() => modal.value,
|
|
() => {
|
|
focused.value = true;
|
|
}
|
|
);
|
|
|
|
function reset() {
|
|
form.name = "";
|
|
form.description = "";
|
|
form.parent = null;
|
|
focused.value = false;
|
|
modal.value = false;
|
|
loading.value = false;
|
|
}
|
|
|
|
const api = useUserApi();
|
|
const toast = useNotifier();
|
|
|
|
async function create() {
|
|
loading.value = true;
|
|
|
|
const { data, error } = await api.locations.create({
|
|
name: form.name,
|
|
description: form.description,
|
|
parentId: form.parent ? form.parent.id : null,
|
|
});
|
|
|
|
if (error) {
|
|
toast.error("Couldn't create location");
|
|
}
|
|
|
|
if (data) {
|
|
toast.success("Location created");
|
|
}
|
|
reset();
|
|
navigateTo(`/location/${data.id}`);
|
|
}
|
|
</script>
|