Skip to content

Commit

Permalink
feat: Add more object (Customer & Product)
Browse files Browse the repository at this point in the history
  • Loading branch information
flemzord committed May 2, 2024
1 parent f789e80 commit d5218d4
Show file tree
Hide file tree
Showing 23 changed files with 750 additions and 347 deletions.
72 changes: 72 additions & 0 deletions apps/web/components/CustomerModal.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<template>
<div>
<UButton @click="ticketsModalOpen = true"
class="block rounded-md bg-indigo-600 px-3 py-2 text-center text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600">
Add customer
</UButton>

<UModal v-model="ticketsModalOpen" prevent-close>
<UCard :ui="{ ring: '', divide: 'divide-y divide-gray-100 dark:divide-gray-800' }">
<template #header>
<div class="flex items-center justify-between">
<h3 class="text-base font-semibold leading-6 text-gray-900 dark:text-white">
Create a new customer
</h3>
<UButton color="gray" variant="ghost" icon="i-heroicons-x-mark-20-solid" class="-my-1" @click="ticketsModalOpen = false" />
</div>
</template>

<template #default>
<UForm :schema="schema" :state="state" class="space-y-4" @submit="onSubmit">
<UFormGroup label="Name of Customer" name="name">
<UInput v-model="state.name" />
</UFormGroup>

<UButton type="submit" class="bg-indigo-600 hover:bg-indigo-900">
Submit
</UButton>
</UForm>
</template>
</UCard>
</UModal>
</div>
</template>

<script setup lang="ts">
const toast = useToast();
const ticketsModalOpen = ref(false);
defineShortcuts({
escape: {
usingInput: true,
whenever: [ticketsModalOpen],
handler: () => {
ticketsModalOpen.value = false;
},
},
});
import { z } from 'zod';
import type { FormSubmitEvent } from '#ui/types';
const schema = z.object({
name: z.string().min(3, 'Must be at least 3 characters'),
});
type Schema = z.output<typeof schema>;
const state = reactive({
name: undefined,
});
async function onSubmit(event: FormSubmitEvent<Schema>) {
const { $client } = useNuxtApp();
const add = await $client.customer.add.mutate(event.data);
ticketsModalOpen.value = false;
toast.add({
title: 'Customer created',
});
await refreshNuxtData();
}
</script>
84 changes: 84 additions & 0 deletions apps/web/components/CustomerTable.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<template>
<div class="relative isolate">
<div class="mx-auto max-w-7xl py-10">
<div class="px-4 sm:px-6 lg:px-8">
<div class="sm:flex sm:items-center">
<div class="sm:flex-auto">
<h1 class="text-base font-semibold leading-6 text-gray-900">Customers</h1>
<p class="mt-2 text-sm text-gray-700">You can create, modify or delete a customer.</p>
</div>
<div class="mt-4 sm:ml-16 sm:mt-0 sm:flex-none">
<CustomerModal />
</div>
</div>
<div class="mt-8 flow-root">
<div class="-mx-4 -my-2 overflow-x-auto sm:-mx-6 lg:-mx-8">
<div class="inline-block min-w-full py-2 align-middle sm:px-6 lg:px-8">
<table class="min-w-full divide-y divide-gray-300">
<thead>
<tr>
<th scope="col" class="py-3.5 pl-4 pr-3 text-left text-sm font-semibold text-gray-900 sm:pl-0">
<a href="#" class="group inline-flex">
Name
<span class="invisible ml-2 flex-none rounded text-gray-400 group-hover:visible group-focus:visible">
<ChevronDownIcon class="h-5 w-5" aria-hidden="true" />
</span>
</a>
</th>
<th scope="col" class="px-3 py-3.5 text-left text-sm font-semibold text-gray-900">
<a href="#" class="group inline-flex">
Created At
<span class="invisible ml-2 flex-none rounded text-gray-400 group-hover:visible group-focus:visible">
<ChevronDownIcon class="invisible ml-2 h-5 w-5 flex-none rounded text-gray-400 group-hover:visible group-focus:visible" aria-hidden="true" />
</span>
</a>
</th>
<th scope="col" class="px-3 py-3.5 text-left text-sm font-semibold text-gray-900">
<a href="#" class="group inline-flex">
Updated At
<span class="invisible ml-2 flex-none rounded text-gray-400 group-hover:visible group-focus:visible">
<ChevronDownIcon class="invisible ml-2 h-5 w-5 flex-none rounded text-gray-400 group-hover:visible group-focus:visible" aria-hidden="true" />
</span>
</a>
</th>
<th scope="col" class="relative py-3.5 pl-3 pr-0">
<span class="sr-only">Edit</span>
</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-200 bg-white">
<tr v-for="token of customer" :key="token.id">
<td class="whitespace-nowrap py-4 pl-4 pr-3 text-sm font-medium text-gray-900 sm:pl-0">{{ token.name }}</td>
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500">{{ token.createdAt }}</td>
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500">{{ token.updatedAt }}</td>
<td class="relative whitespace-nowrap py-4 pl-3 pr-4 text-right text-sm sm:pr-0">
<UButton @click="deleteToken(token.id)" class="bg-red-600 hover:bg-red-500">
Delete
</UButton>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</template>

<script setup>
import { ChevronDownIcon } from '@heroicons/vue/20/solid';
const toast = useToast();
const { $client } = useNuxtApp();
const { data: customer } = await $client.customer.all.useQuery();
async function deleteToken(id) {
console.log('deleteToken', id);
await $client.customer.delete.mutate({ id });
toast.add({ title: 'Customer deleted', timeout: 5000, color: 'red' });
await refreshNuxtData();
}
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<template #header>
<div class="flex items-center justify-between">
<h3 class="text-base font-semibold leading-6 text-gray-900 dark:text-white">
Create a new licence
Create a new license
</h3>
<UButton color="gray" variant="ghost" icon="i-heroicons-x-mark-20-solid" class="-my-1" @click="ticketsModalOpen = false" />
</div>
Expand Down Expand Up @@ -62,7 +62,7 @@ const state = reactive({
async function onSubmit(event: FormSubmitEvent<Schema>) {
const { $client } = useNuxtApp();
const add = await $client.tokens.add.mutate(event.data);
const add = await $client.license.add.mutate(event.data);
console.log('add', add[0].token);
ticketsModalOpen.value = false;
toast.add({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<p class="mt-2 text-sm text-gray-700">You can create, modify or delete a license.</p>
</div>
<div class="mt-4 sm:ml-16 sm:mt-0 sm:flex-none">
<TokensModal />
<LicenseModal />
</div>
</div>
<div class="mt-8 flow-root">
Expand Down Expand Up @@ -47,7 +47,7 @@
</tr>
</thead>
<tbody class="divide-y divide-gray-200 bg-white">
<tr v-for="token of tokens" :key="token.id">
<tr v-for="token of license" :key="token.id">
<td class="whitespace-nowrap py-4 pl-4 pr-3 text-sm font-medium text-gray-900 sm:pl-0">{{ token.name }}</td>
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500">{{ token.createdAt }}</td>
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500">{{ token.updatedAt }}</td>
Expand All @@ -73,11 +73,11 @@ const toast = useToast();
const { $client } = useNuxtApp();
const { data: tokens } = await $client.tokens.all.useQuery();
const { data: license } = await $client.license.all.useQuery();
async function deleteToken(id) {
console.log('deleteToken', id);
await $client.tokens.delete.mutate({ id });
await $client.license.delete.mutate({ id });
toast.add({ title: 'License deleted', timeout: 5000, color: 'red' });
await refreshNuxtData();
}
Expand Down
72 changes: 72 additions & 0 deletions apps/web/components/ProductModal.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<template>
<div>
<UButton @click="ticketsModalOpen = true"
class="block rounded-md bg-indigo-600 px-3 py-2 text-center text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600">
Add product
</UButton>

<UModal v-model="ticketsModalOpen" prevent-close>
<UCard :ui="{ ring: '', divide: 'divide-y divide-gray-100 dark:divide-gray-800' }">
<template #header>
<div class="flex items-center justify-between">
<h3 class="text-base font-semibold leading-6 text-gray-900 dark:text-white">
Create a new product
</h3>
<UButton color="gray" variant="ghost" icon="i-heroicons-x-mark-20-solid" class="-my-1" @click="ticketsModalOpen = false" />
</div>
</template>

<template #default>
<UForm :schema="schema" :state="state" class="space-y-4" @submit="onSubmit">
<UFormGroup label="Name of Product" name="name">
<UInput v-model="state.name" />
</UFormGroup>

<UButton type="submit" class="bg-indigo-600 hover:bg-indigo-900">
Submit
</UButton>
</UForm>
</template>
</UCard>
</UModal>
</div>
</template>

<script setup lang="ts">
const toast = useToast();
const ticketsModalOpen = ref(false);
defineShortcuts({
escape: {
usingInput: true,
whenever: [ticketsModalOpen],
handler: () => {
ticketsModalOpen.value = false;
},
},
});
import { z } from 'zod';
import type { FormSubmitEvent } from '#ui/types';
const schema = z.object({
name: z.string().min(3, 'Must be at least 3 characters'),
});
type Schema = z.output<typeof schema>;
const state = reactive({
name: undefined,
});
async function onSubmit(event: FormSubmitEvent<Schema>) {
const { $client } = useNuxtApp();
const add = await $client.product.add.mutate(event.data);
ticketsModalOpen.value = false;
toast.add({
title: 'Product created',
});
await refreshNuxtData();
}
</script>
84 changes: 84 additions & 0 deletions apps/web/components/ProductTable.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<template>
<div class="relative isolate">
<div class="mx-auto max-w-7xl py-10">
<div class="px-4 sm:px-6 lg:px-8">
<div class="sm:flex sm:items-center">
<div class="sm:flex-auto">
<h1 class="text-base font-semibold leading-6 text-gray-900">Products</h1>
<p class="mt-2 text-sm text-gray-700">You can create, modify or delete a product.</p>
</div>
<div class="mt-4 sm:ml-16 sm:mt-0 sm:flex-none">
<ProductModal />
</div>
</div>
<div class="mt-8 flow-root">
<div class="-mx-4 -my-2 overflow-x-auto sm:-mx-6 lg:-mx-8">
<div class="inline-block min-w-full py-2 align-middle sm:px-6 lg:px-8">
<table class="min-w-full divide-y divide-gray-300">
<thead>
<tr>
<th scope="col" class="py-3.5 pl-4 pr-3 text-left text-sm font-semibold text-gray-900 sm:pl-0">
<a href="#" class="group inline-flex">
Name
<span class="invisible ml-2 flex-none rounded text-gray-400 group-hover:visible group-focus:visible">
<ChevronDownIcon class="h-5 w-5" aria-hidden="true" />
</span>
</a>
</th>
<th scope="col" class="px-3 py-3.5 text-left text-sm font-semibold text-gray-900">
<a href="#" class="group inline-flex">
Created At
<span class="invisible ml-2 flex-none rounded text-gray-400 group-hover:visible group-focus:visible">
<ChevronDownIcon class="invisible ml-2 h-5 w-5 flex-none rounded text-gray-400 group-hover:visible group-focus:visible" aria-hidden="true" />
</span>
</a>
</th>
<th scope="col" class="px-3 py-3.5 text-left text-sm font-semibold text-gray-900">
<a href="#" class="group inline-flex">
Updated At
<span class="invisible ml-2 flex-none rounded text-gray-400 group-hover:visible group-focus:visible">
<ChevronDownIcon class="invisible ml-2 h-5 w-5 flex-none rounded text-gray-400 group-hover:visible group-focus:visible" aria-hidden="true" />
</span>
</a>
</th>
<th scope="col" class="relative py-3.5 pl-3 pr-0">
<span class="sr-only">Edit</span>
</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-200 bg-white">
<tr v-for="token of product" :key="token.id">
<td class="whitespace-nowrap py-4 pl-4 pr-3 text-sm font-medium text-gray-900 sm:pl-0">{{ token.name }}</td>
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500">{{ token.createdAt }}</td>
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500">{{ token.updatedAt }}</td>
<td class="relative whitespace-nowrap py-4 pl-3 pr-4 text-right text-sm sm:pr-0">
<UButton @click="deleteToken(token.id)" class="bg-red-600 hover:bg-red-500">
Delete
</UButton>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</template>

<script setup>
import { ChevronDownIcon } from '@heroicons/vue/20/solid';
const toast = useToast();
const { $client } = useNuxtApp();
const { data: product } = await $client.product.all.useQuery();
async function deleteToken(id) {
console.log('deleteToken', id);
await $client.product.delete.mutate({ id });
toast.add({ title: 'Product deleted', timeout: 5000, color: 'red' });
await refreshNuxtData();
}
</script>
8 changes: 6 additions & 2 deletions apps/web/pages/dashboard/index.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<script setup lang="ts">
import TokensTable from '~/components/TokensTable.vue';
import CustomerTable from '~/components/CustomerTable.vue';
import TokensTable from '~/components/LicenseTable.vue';
import ProductTable from '~/components/ProductTable.vue';
definePageMeta({
layout: 'dashboard',
Expand Down Expand Up @@ -32,6 +34,8 @@ useSeoMeta({
</div>
</header>

<TokensTable />
<ProductTable />
<CustomerTable />
<LicenseTable />
</main>
</template>
Loading

0 comments on commit d5218d4

Please sign in to comment.