Skip to content

Commit

Permalink
Transition to composition API
Browse files Browse the repository at this point in the history
  • Loading branch information
mchev committed Apr 24, 2024
1 parent 3f8ce12 commit 9976cd9
Show file tree
Hide file tree
Showing 26 changed files with 719 additions and 950 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
},
"devDependencies": {
"@inertiajs/vue3": "^1.0.15",
"@popperjs/core": "^2.11.0",
"@vitejs/plugin-vue": "^5.0.4",
"@vue/server-renderer": "^3.2.27",
"autoprefixer": "^10.4.19",
Expand Down
54 changes: 20 additions & 34 deletions resources/js/Pages/Auth/Login.vue
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
<script setup>
import { Head, useForm } from '@inertiajs/vue3'
import Logo from '@/Shared/Logo.vue'
import TextInput from '@/Shared/TextInput.vue'
import LoadingButton from '@/Shared/LoadingButton.vue'
const form = useForm({
email: '[email protected]',
password: 'secret',
remember: false,
});
const login = () => {
form.post('/login')
};
</script>
<template>
<Head title="Login" />
<div class="flex items-center justify-center p-6 min-h-screen bg-indigo-800">
Expand All @@ -7,47 +23,17 @@
<div class="px-10 py-12">
<h1 class="text-center text-3xl font-bold">Welcome Back!</h1>
<div class="mt-6 mx-auto w-24 border-b-2" />
<text-input v-model="form.email" :error="form.errors.email" class="mt-10" label="Email" type="email" autofocus autocapitalize="off" />
<text-input v-model="form.password" :error="form.errors.password" class="mt-6" label="Password" type="password" />
<TextInput v-model="form.email" :error="form.errors.email" class="mt-10" label="Email" type="email" autofocus autocapitalize="off" />
<TextInput v-model="form.password" :error="form.errors.password" class="mt-6" label="Password" type="password" />
<label class="flex items-center mt-6 select-none" for="remember">
<input id="remember" v-model="form.remember" class="mr-1" type="checkbox" />
<span class="text-sm">Remember Me</span>
</label>
</div>
<div class="flex px-10 py-4 bg-gray-100 border-t border-gray-100">
<loading-button :loading="form.processing" class="btn-indigo ml-auto" type="submit">Login</loading-button>
<LoadingButton :loading="form.processing" class="btn-indigo ml-auto" type="submit">Login</LoadingButton>
</div>
</form>
</div>
</div>
</template>

<script>
import { Head } from '@inertiajs/vue3'
import Logo from '@/Shared/Logo.vue'
import TextInput from '@/Shared/TextInput.vue'
import LoadingButton from '@/Shared/LoadingButton.vue'
export default {
components: {
Head,
LoadingButton,
Logo,
TextInput,
},
data() {
return {
form: this.$inertia.form({
email: '[email protected]',
password: 'secret',
remember: false,
}),
}
},
methods: {
login() {
this.form.post('/login')
},
},
}
</script>
</template>
102 changes: 43 additions & 59 deletions resources/js/Pages/Contacts/Create.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
<script setup>
import { Head, Link, useForm } from '@inertiajs/vue3'
import Layout from '@/Shared/Layout.vue'
import TextInput from '@/Shared/TextInput.vue'
import SelectInput from '@/Shared/SelectInput.vue'
import LoadingButton from '@/Shared/LoadingButton.vue'
defineProps({
organizations: Array,
});
const form = useForm({
first_name: '',
last_name: '',
organization_id: null,
email: '',
phone: '',
address: '',
city: '',
region: '',
country: '',
postal_code: '',
});
const store = () => {
form.post('/contacts')
};
</script>
<template>
<div>
<Layout>
<Head title="Create Contact" />
<h1 class="mb-8 text-3xl font-bold">
<Link class="text-indigo-400 hover:text-indigo-600" href="/contacts">Contacts</Link>
Expand All @@ -8,72 +36,28 @@
<div class="max-w-3xl bg-white rounded-md shadow overflow-hidden">
<form @submit.prevent="store">
<div class="flex flex-wrap -mb-8 -mr-6 p-8">
<text-input v-model="form.first_name" :error="form.errors.first_name" class="pb-8 pr-6 w-full lg:w-1/2" label="First name" />
<text-input v-model="form.last_name" :error="form.errors.last_name" class="pb-8 pr-6 w-full lg:w-1/2" label="Last name" />
<select-input v-model="form.organization_id" :error="form.errors.organization_id" class="pb-8 pr-6 w-full lg:w-1/2" label="Organization">
<TextInput v-model="form.first_name" :error="form.errors.first_name" class="pb-8 pr-6 w-full lg:w-1/2" label="First name" />
<TextInput v-model="form.last_name" :error="form.errors.last_name" class="pb-8 pr-6 w-full lg:w-1/2" label="Last name" />
<SelectInput v-model="form.organization_id" :error="form.errors.organization_id" class="pb-8 pr-6 w-full lg:w-1/2" label="Organization">
<option :value="null" />
<option v-for="organization in organizations" :key="organization.id" :value="organization.id">{{ organization.name }}</option>
</select-input>
<text-input v-model="form.email" :error="form.errors.email" class="pb-8 pr-6 w-full lg:w-1/2" label="Email" />
<text-input v-model="form.phone" :error="form.errors.phone" class="pb-8 pr-6 w-full lg:w-1/2" label="Phone" />
<text-input v-model="form.address" :error="form.errors.address" class="pb-8 pr-6 w-full lg:w-1/2" label="Address" />
<text-input v-model="form.city" :error="form.errors.city" class="pb-8 pr-6 w-full lg:w-1/2" label="City" />
<text-input v-model="form.region" :error="form.errors.region" class="pb-8 pr-6 w-full lg:w-1/2" label="Province/State" />
<select-input v-model="form.country" :error="form.errors.country" class="pb-8 pr-6 w-full lg:w-1/2" label="Country">
</SelectInput>
<TextInput v-model="form.email" :error="form.errors.email" class="pb-8 pr-6 w-full lg:w-1/2" label="Email" />
<TextInput v-model="form.phone" :error="form.errors.phone" class="pb-8 pr-6 w-full lg:w-1/2" label="Phone" />
<TextInput v-model="form.address" :error="form.errors.address" class="pb-8 pr-6 w-full lg:w-1/2" label="Address" />
<TextInput v-model="form.city" :error="form.errors.city" class="pb-8 pr-6 w-full lg:w-1/2" label="City" />
<TextInput v-model="form.region" :error="form.errors.region" class="pb-8 pr-6 w-full lg:w-1/2" label="Province/State" />
<SelectInput v-model="form.country" :error="form.errors.country" class="pb-8 pr-6 w-full lg:w-1/2" label="Country">
<option :value="null" />
<option value="CA">Canada</option>
<option value="US">United States</option>
</select-input>
<text-input v-model="form.postal_code" :error="form.errors.postal_code" class="pb-8 pr-6 w-full lg:w-1/2" label="Postal code" />
</SelectInput>
<TextInput v-model="form.postal_code" :error="form.errors.postal_code" class="pb-8 pr-6 w-full lg:w-1/2" label="Postal code" />
</div>
<div class="flex items-center justify-end px-8 py-4 bg-gray-50 border-t border-gray-100">
<loading-button :loading="form.processing" class="btn-indigo" type="submit">Create Contact</loading-button>
<LoadingButton :loading="form.processing" class="btn-indigo" type="submit">Create Contact</LoadingButton>
</div>
</form>
</div>
</div>
</Layout>
</template>

<script>
import { Head, Link } from '@inertiajs/vue3'
import Layout from '@/Shared/Layout.vue'
import TextInput from '@/Shared/TextInput.vue'
import SelectInput from '@/Shared/SelectInput.vue'
import LoadingButton from '@/Shared/LoadingButton.vue'
export default {
components: {
Head,
Link,
LoadingButton,
SelectInput,
TextInput,
},
layout: Layout,
props: {
organizations: Array,
},
remember: 'form',
data() {
return {
form: this.$inertia.form({
first_name: '',
last_name: '',
organization_id: null,
email: '',
phone: '',
address: '',
city: '',
region: '',
country: '',
postal_code: '',
}),
}
},
methods: {
store() {
this.form.post('/contacts')
},
},
}
</script>
133 changes: 59 additions & 74 deletions resources/js/Pages/Contacts/Edit.vue
Original file line number Diff line number Diff line change
@@ -1,95 +1,80 @@
<script setup>
import { Head, Link, useForm, router } from '@inertiajs/vue3'
import Layout from '@/Shared/Layout.vue'
import TextInput from '@/Shared/TextInput.vue'
import SelectInput from '@/Shared/SelectInput.vue'
import LoadingButton from '@/Shared/LoadingButton.vue'
import TrashedMessage from '@/Shared/TrashedMessage.vue'
const props = defineProps({
contact: Object,
organizations: Array,
});
const form = useForm({
first_name: props.contact.first_name,
last_name: props.contact.last_name,
organization_id: props.contact.organization_id,
email: props.contact.email,
phone: props.contact.phone,
address: props.contact.address,
city: props.contact.city,
region: props.contact.region,
country: props.contact.country,
postal_code: props.contact.postal_code,
});
const update = () => {
form.put(`/contacts/${props.contact.id}`)
};
const destroy = () => {
if (confirm('Are you sure you want to delete this contact?')) {
router.delete(`/contacts/${props.contact.id}`)
}
};
const restore = () => {
if (confirm('Are you sure you want to restore this contact?')) {
router.put(`/contacts/${props.contact.id}/restore`)
}
};
</script>
<template>
<div>
<Layout>
<Head :title="`${form.first_name} ${form.last_name}`" />
<h1 class="mb-8 text-3xl font-bold">
<Link class="text-indigo-400 hover:text-indigo-600" href="/contacts">Contacts</Link>
<span class="text-indigo-400 font-medium">/</span>
{{ form.first_name }} {{ form.last_name }}
</h1>
<trashed-message v-if="contact.deleted_at" class="mb-6" @restore="restore"> This contact has been deleted. </trashed-message>
<TrashedMessage v-if="contact.deleted_at" class="mb-6" @restore="restore"> This contact has been deleted. </TrashedMessage>
<div class="max-w-3xl bg-white rounded-md shadow overflow-hidden">
<form @submit.prevent="update">
<div class="flex flex-wrap -mb-8 -mr-6 p-8">
<text-input v-model="form.first_name" :error="form.errors.first_name" class="pb-8 pr-6 w-full lg:w-1/2" label="First name" />
<text-input v-model="form.last_name" :error="form.errors.last_name" class="pb-8 pr-6 w-full lg:w-1/2" label="Last name" />
<select-input v-model="form.organization_id" :error="form.errors.organization_id" class="pb-8 pr-6 w-full lg:w-1/2" label="Organization">
<TextInput v-model="form.first_name" :error="form.errors.first_name" class="pb-8 pr-6 w-full lg:w-1/2" label="First name" />
<TextInput v-model="form.last_name" :error="form.errors.last_name" class="pb-8 pr-6 w-full lg:w-1/2" label="Last name" />
<SelectInput v-model="form.organization_id" :error="form.errors.organization_id" class="pb-8 pr-6 w-full lg:w-1/2" label="Organization">
<option :value="null" />
<option v-for="organization in organizations" :key="organization.id" :value="organization.id">{{ organization.name }}</option>
</select-input>
<text-input v-model="form.email" :error="form.errors.email" class="pb-8 pr-6 w-full lg:w-1/2" label="Email" />
<text-input v-model="form.phone" :error="form.errors.phone" class="pb-8 pr-6 w-full lg:w-1/2" label="Phone" />
<text-input v-model="form.address" :error="form.errors.address" class="pb-8 pr-6 w-full lg:w-1/2" label="Address" />
<text-input v-model="form.city" :error="form.errors.city" class="pb-8 pr-6 w-full lg:w-1/2" label="City" />
<text-input v-model="form.region" :error="form.errors.region" class="pb-8 pr-6 w-full lg:w-1/2" label="Province/State" />
<select-input v-model="form.country" :error="form.errors.country" class="pb-8 pr-6 w-full lg:w-1/2" label="Country">
</SelectInput>
<TextInput v-model="form.email" :error="form.errors.email" class="pb-8 pr-6 w-full lg:w-1/2" label="Email" />
<TextInput v-model="form.phone" :error="form.errors.phone" class="pb-8 pr-6 w-full lg:w-1/2" label="Phone" />
<TextInput v-model="form.address" :error="form.errors.address" class="pb-8 pr-6 w-full lg:w-1/2" label="Address" />
<TextInput v-model="form.city" :error="form.errors.city" class="pb-8 pr-6 w-full lg:w-1/2" label="City" />
<TextInput v-model="form.region" :error="form.errors.region" class="pb-8 pr-6 w-full lg:w-1/2" label="Province/State" />
<SelectInput v-model="form.country" :error="form.errors.country" class="pb-8 pr-6 w-full lg:w-1/2" label="Country">
<option :value="null" />
<option value="CA">Canada</option>
<option value="US">United States</option>
</select-input>
<text-input v-model="form.postal_code" :error="form.errors.postal_code" class="pb-8 pr-6 w-full lg:w-1/2" label="Postal code" />
</SelectInput>
<TextInput v-model="form.postal_code" :error="form.errors.postal_code" class="pb-8 pr-6 w-full lg:w-1/2" label="Postal code" />
</div>
<div class="flex items-center px-8 py-4 bg-gray-50 border-t border-gray-100">
<button v-if="!contact.deleted_at" class="text-red-600 hover:underline" tabindex="-1" type="button" @click="destroy">Delete Contact</button>
<loading-button :loading="form.processing" class="btn-indigo ml-auto" type="submit">Update Contact</loading-button>
<LoadingButton :loading="form.processing" class="btn-indigo ml-auto" type="submit">Update Contact</LoadingButton>
</div>
</form>
</div>
</div>
</template>

<script>
import { Head, Link } from '@inertiajs/vue3'
import Layout from '@/Shared/Layout.vue'
import TextInput from '@/Shared/TextInput.vue'
import SelectInput from '@/Shared/SelectInput.vue'
import LoadingButton from '@/Shared/LoadingButton.vue'
import TrashedMessage from '@/Shared/TrashedMessage.vue'
export default {
components: {
Head,
Link,
LoadingButton,
SelectInput,
TextInput,
TrashedMessage,
},
layout: Layout,
props: {
contact: Object,
organizations: Array,
},
remember: 'form',
data() {
return {
form: this.$inertia.form({
first_name: this.contact.first_name,
last_name: this.contact.last_name,
organization_id: this.contact.organization_id,
email: this.contact.email,
phone: this.contact.phone,
address: this.contact.address,
city: this.contact.city,
region: this.contact.region,
country: this.contact.country,
postal_code: this.contact.postal_code,
}),
}
},
methods: {
update() {
this.form.put(`/contacts/${this.contact.id}`)
},
destroy() {
if (confirm('Are you sure you want to delete this contact?')) {
this.$inertia.delete(`/contacts/${this.contact.id}`)
}
},
restore() {
if (confirm('Are you sure you want to restore this contact?')) {
this.$inertia.put(`/contacts/${this.contact.id}/restore`)
}
},
},
}
</script>
</Layout>
</template>
Loading

0 comments on commit 9976cd9

Please sign in to comment.