Teren-app/resources/js/Pages/Client/Index.vue
Simon Pocrnjič 90a5858320 first commit
2024-10-28 21:08:16 +01:00

188 lines
7.2 KiB
Vue

<script setup>
import { ref } from 'vue';
import AppLayout from '@/Layouts/AppLayout.vue';
import List from '@/Components/List.vue';
import ListItem from '@/Components/ListItem.vue';
import PrimaryButton from '@/Components/PrimaryButton.vue';
import InputLabel from '@/Components/InputLabel.vue';
import TextInput from '@/Components/TextInput.vue';
import { useForm } from '@inertiajs/vue3';
import ActionMessage from '@/Components/ActionMessage.vue';
import Drawer from '@/Components/Drawer.vue';
const props = defineProps({
persons: Array,
create_url: String,
person_types: Array
});
const drawerCreateClient = ref(false);
const Address = {
address: '',
country: '',
type_id: 1
};
const formClient = useForm({
first_name: '',
last_name: '',
full_name: '',
address: Address
});
const openDrawerCreateClient = () => {
drawerCreateClient.value = true
}
const closeDrawer = () => {
drawerCreateClient.value = false
}
const storeClient = () => {
formClient.post(route('client.store'), {
onBefore: () => {
formClient.address.type_id = Number(formClient.address.type_id);
},
onSuccess: () => {
closeDrawer();
formClient.reset();
}
});
};
</script>
<template>
<AppLayout title="Client">
<template #header>
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
Clients
</h2>
</template>
<div class="py-12">
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
<div class="px-3 bg-white overflow-hidden shadow-xl sm:rounded-lg">
<div class="mx-auto max-w-4x1 py-3">
<PrimaryButton @click="openDrawerCreateClient" class="bg-blue-400">Add client</PrimaryButton>
<List class="mt-2">
<ListItem v-for="person in persons">
<div class="flex justify-between shadow rounded border-solid border-l-4 border-blue-400 p-3">
<div class="flex min-w-0 gap-x-4">
<div class="min-w-0 flex-auto">
<p class="text-sm font-semibold leading-6 text-gray-900"><a :href="route('client.show', { uuid: person.uuid })">{{ person.full_name }}</a></p>
<p class="mt-1 truncate text-xs leading-5 text-gray-500">{{ person.nu }}</p>
</div>
</div>
<div class="hidden shrink-0 sm:flex sm:flex-col sm:items-end">
<p class="text-sm leading-6 text-gray-900">{{ person.tax_number }}</p>
<div class="mt-1 flex items-center gap-x-1.5">
<p class="text-xs leading-5 text-gray-500">{{ person.group.name }}</p>
</div>
</div>
</div>
</ListItem>
</List>
</div>
</div>
</div>
</div>
</AppLayout>
<Drawer
:show="drawerCreateClient"
@close="drawerCreateClient = false"
>
<template #title>Add client</template>
<template #content>
<form @submit.prevent="storeClient">
<div>
<div class="col-span-6 sm:col-span-4">
<InputLabel for="firstname" value="First name"/>
<TextInput
id="firstname"
ref="firstnameInput"
v-model="formClient.first_name"
type="text"
class="mt-1 block w-full"
autocomplete="first-name"
/>
</div>
<div class="col-span-6 sm:col-span-4">
<InputLabel for="lastname" value="Last name"/>
<TextInput
id="lastname"
ref="lastnameInput"
v-model="formClient.last_name"
type="text"
class="mt-1 block w-full"
autocomplete="last-name"
/>
</div>
<div class="col-span-6 sm:col-span-4">
<InputLabel for="fullname" value="Full name"/>
<TextInput
id="fullname"
ref="fullnameInput"
v-model="formClient.full_name"
type="text"
class="mt-1 block w-full"
autocomplete="full-name"
/>
</div>
<div class="col-span-6 sm:col-span-4">
<InputLabel for="address" value="Address"/>
<TextInput
id="address"
ref="addressInput"
v-model="formClient.address.address"
type="text"
class="mt-1 block w-full"
autocomplete="address"
/>
</div>
<div class="col-span-6 sm:col-span-4">
<InputLabel for="addressCountry" value="Country"/>
<TextInput
id="addressCountry"
ref="addressCountryInput"
v-model="formClient.address.country"
type="text"
class="mt-1 block w-full"
autocomplete="address-country"
/>
</div>
<div class="col-span-6 sm:col-span-4">
<InputLabel for="addressType" value="Address type"/>
<select
class="block w-full border-gray-300 focus:border-indigo-500 focus:ring-indigo-500 rounded-md shadow-sm"
id="addressType"
v-model="formClient.address.type_id"
>
<option value="1">Permanent</option>
<option value="2">Temporary</option>
<!-- ... -->
</select>
</div>
</div>
<div class="flex justify-end mt-4">
<ActionMessage :on="formClient.recentlySuccessful" class="me-3">
Saved.
</ActionMessage>
<PrimaryButton :class="{ 'opacity-25': formClient.processing }" :disabled="formClient.processing">
Save
</PrimaryButton>
</div>
</form>
</template>
</Drawer>
</template>