mirror of
https://github.com/ArthurDanjou/website-old.git
synced 2026-01-28 19:00:34 +01:00
Fix form fill
This commit is contained in:
@@ -14,7 +14,6 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
* {
|
* {
|
||||||
@apply select-none outline-none;
|
|
||||||
font-family: 'Raleway', sans-serif;
|
font-family: 'Raleway', sans-serif;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
<div class="form-div lg:w-1/2 mb-8 lg:mb-0">
|
<div class="form-div lg:w-1/2 mb-8 lg:mb-0">
|
||||||
<input
|
<input
|
||||||
id="name"
|
id="name"
|
||||||
|
v-model="form.name"
|
||||||
required
|
required
|
||||||
type="text"
|
type="text"
|
||||||
placeholder=" "
|
placeholder=" "
|
||||||
@@ -18,6 +19,7 @@
|
|||||||
<div class="form-div lg:w-1/2">
|
<div class="form-div lg:w-1/2">
|
||||||
<input
|
<input
|
||||||
id="email"
|
id="email"
|
||||||
|
v-model="form.email"
|
||||||
required
|
required
|
||||||
type="email"
|
type="email"
|
||||||
placeholder=" "
|
placeholder=" "
|
||||||
@@ -29,6 +31,7 @@
|
|||||||
<div class="form-div w-full mb-8 lg:mb-12">
|
<div class="form-div w-full mb-8 lg:mb-12">
|
||||||
<input
|
<input
|
||||||
id="subject"
|
id="subject"
|
||||||
|
v-model="form.subject"
|
||||||
required
|
required
|
||||||
type="text"
|
type="text"
|
||||||
placeholder=" "
|
placeholder=" "
|
||||||
@@ -39,6 +42,7 @@
|
|||||||
<div class="form-div w-full">
|
<div class="form-div w-full">
|
||||||
<textarea
|
<textarea
|
||||||
id="content"
|
id="content"
|
||||||
|
v-model="form.content"
|
||||||
required
|
required
|
||||||
placeholder=" "
|
placeholder=" "
|
||||||
class="form-input w-full"
|
class="form-input w-full"
|
||||||
@@ -48,17 +52,71 @@
|
|||||||
<label for="content" class="form-label">{{ $t('contact.form.content') }}</label>
|
<label for="content" class="form-label">{{ $t('contact.form.content') }}</label>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
<div v-if="error" class="mt-4 px-3 py-1 rounded-full bg-red-300 font-bold text-black">
|
||||||
|
{{ $t('contact.form.error') }}
|
||||||
|
</div>
|
||||||
|
<div v-if="success" class="mt-4 px-3 py-1 rounded-full bg-green-300 font-bold text-black">
|
||||||
|
{{ $t('contact.form.success') }}
|
||||||
|
</div>
|
||||||
<div class="my-12">
|
<div class="my-12">
|
||||||
<div class="font-bold px-6 py-3 border-2 rounded-full border-indigo-600 text-indigo-600 hover:(bg-indigo-600 text-white) hover:dark:text-black duration-300 cursor-pointer">
|
<button :disabled="!isSendable" @click.prevent="handleForm" class="font-bold px-6 py-3 border-2 rounded-full border-indigo-600 text-indigo-600 hover:(bg-indigo-600 text-white) hover:dark:text-black duration-300 cursor-pointer">
|
||||||
{{ $t('contact.form.submit') }}
|
{{ $t('contact.form.submit') }}
|
||||||
</div>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import {computed, ref, useContext} from "@nuxtjs/composition-api";
|
||||||
|
import {Form} from "../../@types/types";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "ContactForm"
|
name: "ContactForm",
|
||||||
|
setup() {
|
||||||
|
const error = ref(false)
|
||||||
|
const success = ref(false)
|
||||||
|
|
||||||
|
const {$axios} = useContext()
|
||||||
|
const form = ref<Form>({} as Form)
|
||||||
|
const handleForm = async () => {
|
||||||
|
await $axios.post('form',
|
||||||
|
{
|
||||||
|
email: form.value.email,
|
||||||
|
name: form.value.name,
|
||||||
|
content: form.value.content,
|
||||||
|
subject: form.value.subject
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
success.value = true
|
||||||
|
setTimeout(() => {
|
||||||
|
success.value = false
|
||||||
|
form.value = {} as Form
|
||||||
|
}, 5000)
|
||||||
|
}).catch(() => {
|
||||||
|
error.value = true
|
||||||
|
setTimeout(() => {
|
||||||
|
error.value = false
|
||||||
|
}, 5000)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const isSendable = computed(() => {
|
||||||
|
const {email, name, content, subject} = form.value
|
||||||
|
return isNotEmpty(email) && isNotEmpty(name) && isNotEmpty(content) && isNotEmpty(subject)
|
||||||
|
})
|
||||||
|
|
||||||
|
const isNotEmpty = (object: string | undefined) => {
|
||||||
|
return object !== undefined && object.length > 0 && object !== "" && object !== ''
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
error,
|
||||||
|
success,
|
||||||
|
isSendable,
|
||||||
|
form,
|
||||||
|
handleForm
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -59,50 +59,9 @@ export default {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const error = ref(false)
|
|
||||||
const success = ref(false)
|
|
||||||
|
|
||||||
const {$axios} = useContext()
|
|
||||||
const form = ref<Form>({} as Form)
|
|
||||||
const handleForm = async () => {
|
|
||||||
await $axios.post('subscribers',
|
|
||||||
{
|
|
||||||
email: form.value.email,
|
|
||||||
name: form.value.name,
|
|
||||||
content: form.value.content,
|
|
||||||
subject: form.value.subject
|
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
success.value = true
|
|
||||||
setTimeout(() => {
|
|
||||||
success.value = false
|
|
||||||
form.value = {} as Form
|
|
||||||
}, 5000)
|
|
||||||
}).catch(() => {
|
|
||||||
error.value = true
|
|
||||||
setTimeout(() => {
|
|
||||||
error.value = false
|
|
||||||
}, 5000)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const isSendable = computed(() => {
|
|
||||||
const {email, name, content, subject} = form.value
|
|
||||||
return isNotEmpty(email) && isNotEmpty(name)
|
|
||||||
})
|
|
||||||
|
|
||||||
const isNotEmpty = (object: string | undefined) => {
|
|
||||||
return object !== undefined && object.length > 0 && object !== "" && object !== ''
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
info,
|
info,
|
||||||
getColor,
|
getColor,
|
||||||
handleForm,
|
|
||||||
success,
|
|
||||||
error,
|
|
||||||
form,
|
|
||||||
isSendable
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
<h1 class="text-gray-700 dark:text-gray-400 text-xl mt-4">{{ $t('projects.description') }}</h1>
|
<h1 class="text-gray-700 dark:text-gray-400 text-xl mt-4">{{ $t('projects.description') }}</h1>
|
||||||
<div class="flex flex-col items-center md:items-start md:flex-row flex-wrap w-full space-y-3 md:space-y-0">
|
<div class="flex flex-col items-center md:items-start md:flex-row flex-wrap w-full space-y-3 md:space-y-0">
|
||||||
<div class="flex py-8 w-full flex-wrap" >
|
<div class="flex py-8 w-full flex-wrap" >
|
||||||
<div class="md:mx-3 my-2 w-full" v-for="project in projects">
|
<div class="md:mx-3 my-2 w-full xl:w-auto" v-for="project in projects">
|
||||||
<Project
|
<Project
|
||||||
:title="project.title"
|
:title="project.title"
|
||||||
:cover="project.cover"
|
:cover="project.cover"
|
||||||
|
|||||||
Reference in New Issue
Block a user