pingcrm/resources/js/Pages/Contacts/Index.vue

112 lines
3.6 KiB
Vue
Raw Normal View History

2019-03-18 08:53:00 -03:00
<template>
<div>
2021-12-08 12:15:39 -03:00
<Head title="Contacts" />
2019-03-18 08:53:00 -03:00
<h1 class="mb-8 font-bold text-3xl">Contacts</h1>
<div class="mb-6 flex justify-between items-center">
<search-filter v-model="form.search" class="w-full max-w-md mr-4" @reset="reset">
2019-05-22 12:39:26 -03:00
<label class="block text-gray-700">Trashed:</label>
2019-03-18 08:53:00 -03:00
<select v-model="form.trashed" class="mt-1 w-full form-select">
<option :value="null" />
<option value="with">With Trashed</option>
<option value="only">Only Trashed</option>
</select>
</search-filter>
2021-12-08 12:15:39 -03:00
<Link class="btn-indigo" href="/contacts/create">
2019-03-18 08:53:00 -03:00
<span>Create</span>
2021-12-08 14:00:56 -03:00
<span class="hidden md:inline">&nbsp;Contact</span>
2021-12-08 12:15:39 -03:00
</Link>
2019-03-18 08:53:00 -03:00
</div>
<div class="bg-white rounded-md shadow overflow-x-auto">
<table class="w-full whitespace-nowrap">
2019-03-18 08:53:00 -03:00
<tr class="text-left font-bold">
<th class="px-6 pt-6 pb-4">Name</th>
<th class="px-6 pt-6 pb-4">Organization</th>
<th class="px-6 pt-6 pb-4">City</th>
<th class="px-6 pt-6 pb-4" colspan="2">Phone</th>
</tr>
<tr v-for="contact in contacts.data" :key="contact.id" class="hover:bg-gray-100 focus-within:bg-gray-100">
2019-03-18 08:53:00 -03:00
<td class="border-t">
2021-12-08 12:15:39 -03:00
<Link class="px-6 py-4 flex items-center focus:text-indigo-500" :href="`/contacts/${contact.id}/edit`">
2019-03-18 08:53:00 -03:00
{{ contact.name }}
2019-05-22 12:39:26 -03:00
<icon v-if="contact.deleted_at" name="trash" class="flex-shrink-0 w-3 h-3 fill-gray-400 ml-2" />
2021-12-08 12:15:39 -03:00
</Link>
2019-03-18 08:53:00 -03:00
</td>
<td class="border-t">
2021-12-08 12:15:39 -03:00
<Link class="px-6 py-4 flex items-center" :href="`/contacts/${contact.id}/edit`" tabindex="-1">
2019-03-18 08:53:00 -03:00
<div v-if="contact.organization">
{{ contact.organization.name }}
</div>
2021-12-08 12:15:39 -03:00
</Link>
2019-03-18 08:53:00 -03:00
</td>
<td class="border-t">
2021-12-08 12:15:39 -03:00
<Link class="px-6 py-4 flex items-center" :href="`/contacts/${contact.id}/edit`" tabindex="-1">
2019-03-18 08:53:00 -03:00
{{ contact.city }}
2021-12-08 12:15:39 -03:00
</Link>
2019-03-18 08:53:00 -03:00
</td>
<td class="border-t">
2021-12-08 12:15:39 -03:00
<Link class="px-6 py-4 flex items-center" :href="`/contacts/${contact.id}/edit`" tabindex="-1">
2019-03-18 08:53:00 -03:00
{{ contact.phone }}
2021-12-08 12:15:39 -03:00
</Link>
2019-03-18 08:53:00 -03:00
</td>
<td class="border-t w-px">
2021-12-08 12:15:39 -03:00
<Link class="px-4 flex items-center" :href="`/contacts/${contact.id}/edit`" tabindex="-1">
2019-05-22 12:39:26 -03:00
<icon name="cheveron-right" class="block w-6 h-6 fill-gray-400" />
2021-12-08 12:15:39 -03:00
</Link>
2019-03-18 08:53:00 -03:00
</td>
</tr>
<tr v-if="contacts.data.length === 0">
<td class="border-t px-6 py-4" colspan="4">No contacts found.</td>
</tr>
</table>
</div>
2021-02-27 10:36:45 -03:00
<pagination class="mt-6" :links="contacts.links" />
</div>
2019-03-18 08:53:00 -03:00
</template>
<script>
2021-12-08 12:15:39 -03:00
import { Head, Link } from '@inertiajs/inertia-vue3'
2019-03-18 08:53:00 -03:00
import Icon from '@/Shared/Icon'
2021-02-27 11:00:09 -03:00
import pickBy from 'lodash/pickBy'
2019-03-18 08:53:00 -03:00
import Layout from '@/Shared/Layout'
2021-02-27 11:00:09 -03:00
import throttle from 'lodash/throttle'
2019-12-18 15:48:33 -03:00
import mapValues from 'lodash/mapValues'
2019-03-18 08:53:00 -03:00
import Pagination from '@/Shared/Pagination'
import SearchFilter from '@/Shared/SearchFilter'
export default {
components: {
2021-12-08 12:15:39 -03:00
Head,
2019-03-18 08:53:00 -03:00
Icon,
2021-12-08 12:15:39 -03:00
Link,
2019-03-18 08:53:00 -03:00
Pagination,
SearchFilter,
},
2021-02-27 11:00:09 -03:00
layout: Layout,
2019-03-18 08:53:00 -03:00
props: {
filters: Object,
2021-05-10 13:41:56 -03:00
contacts: Object,
2019-03-18 08:53:00 -03:00
},
data() {
return {
form: {
search: this.filters.search,
trashed: this.filters.trashed,
},
}
},
watch: {
form: {
deep: true,
2019-12-18 15:48:33 -03:00
handler: throttle(function() {
2021-12-08 12:15:39 -03:00
this.$inertia.get('/contacts', pickBy(this.form), { preserveState: true })
2019-03-18 08:53:00 -03:00
}, 150),
},
},
methods: {
reset() {
2019-12-18 15:48:33 -03:00
this.form = mapValues(this.form, () => null)
2019-03-18 08:53:00 -03:00
},
},
}
</script>