Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transition to composition API #212

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ module.exports = {
semi: ['warn', 'never'],
'no-unused-vars': ['error', { vars: 'all', args: 'after-used', ignoreRestSiblings: true }],
'comma-dangle': ['warn', 'always-multiline'],
'vue/component-api-style': [
'error',
['script-setup', 'composition', 'options'],
],
'vue/multi-word-component-names': 'off',
'vue/max-attributes-per-line': 'off',
'vue/no-v-html': 'off',
Expand Down
868 changes: 438 additions & 430 deletions package-lock.json

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,17 @@
},
"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",
"eslint": "^8.4.1",
"eslint-plugin-vue": "^8.2.0",
"eslint": "^9.1.1",
"eslint-plugin-vue": "^9.25.0",
"laravel-vite-plugin": "^1.0.2",
"lodash": "^4.17.21",
"postcss": "^8.4.38",
"postcss-import": "^16.1.0",
"prettier": "^2.5.1",
"prettier-plugin-tailwind": "^2.2.12",
"prettier": "^3.2.5",
"prettier-plugin-tailwindcss": "^0.5.14",
"tailwindcss": "^3.4.3",
"uuid": "^8.3.2",
"vite": "^5.2.7",
Expand Down
52 changes: 19 additions & 33 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>
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>
131 changes: 58 additions & 73 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>
</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'
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>
Loading
Loading