1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
|
import { ButtonSubmit } from '@components/Buttons';
import { Form, FormItem, Input, TextArea } from '@components/Form';
import { getLayout } from '@components/Layouts/Layout';
import { seo } from '@config/seo';
import { t } from '@lingui/macro';
import { sendMail } from '@services/graphql/mutations';
import { NextPageWithLayout } from '@ts/types/app';
import { defaultLocale, loadTranslation } from '@utils/helpers/i18n';
import { GetStaticProps, GetStaticPropsContext } from 'next';
import Head from 'next/head';
import { FormEvent, useState } from 'react';
import PostHeader from '@components/PostHeader/PostHeader';
import styles from '@styles/pages/Page.module.scss';
import { SocialMedia } from '@components/Widgets';
import Sidebar from '@components/Sidebar/Sidebar';
import { ContactPage as ContactPageSchema, Graph, WebPage } from 'schema-dts';
import { config } from '@config/website';
import { useRouter } from 'next/router';
const ContactPage: NextPageWithLayout = () => {
const [name, setName] = useState('');
const [email, setEmail] = useState('');
const [subject, setSubject] = useState('');
const [message, setMessage] = useState('');
const [status, setStatus] = useState('');
const router = useRouter();
const resetForm = () => {
setName('');
setEmail('');
setSubject('');
setMessage('');
};
const submitHandler = async (e: FormEvent) => {
e.preventDefault();
const body = `Message received from ${name} <${email}> on ArmandPhilippot.com.\n\n${message}`;
const replyTo = `${name} <${email}>`;
const data = {
body,
mutationId: 'contact',
replyTo,
subject,
};
const mail = await sendMail(data);
if (mail.sent) {
setStatus(
t`Thanks. Your message was successfully sent. I will answer it as soon as possible.`
);
resetForm();
} else {
const errorPrefix = t`An error occurred:`;
const error = `${errorPrefix} ${mail.message}`;
setStatus(error);
}
};
const title = t`Contact`;
const intro = t`Please fill the form to contact me.`;
const pageUrl = `${config.url}${router.asPath}`;
const webpageSchema: WebPage = {
'@id': `${pageUrl}`,
'@type': 'WebPage',
breadcrumb: { '@id': `${config.url}/#breadcrumb` },
name: seo.contact.title,
description: seo.contact.description,
reviewedBy: { '@id': `${config.url}/#branding` },
url: `${pageUrl}`,
isPartOf: {
'@id': `${config.url}`,
},
};
const contactSchema: ContactPageSchema = {
'@id': `${config.url}/#contact`,
'@type': 'ContactPage',
name: title,
description: intro,
author: { '@id': `${config.url}/#branding` },
creator: { '@id': `${config.url}/#branding` },
editor: { '@id': `${config.url}/#branding` },
inLanguage: config.locales.defaultLocale,
license: 'https://creativecommons.org/licenses/by-sa/4.0/deed.fr',
mainEntityOfPage: { '@id': `${pageUrl}` },
};
const schemaJsonLd: Graph = {
'@context': 'https://schema.org',
'@graph': [webpageSchema, contactSchema],
};
return (
<>
<Head>
<title>{seo.contact.title}</title>
<meta name="description" content={seo.contact.description} />
<meta property="og:url" content={`${pageUrl}`} />
<meta property="og:type" content="article" />
<meta property="og:title" content={title} />
<meta property="og:description" content={intro} />
<script
type="application/ld+json"
dangerouslySetInnerHTML={{ __html: JSON.stringify(schemaJsonLd) }}
></script>
</Head>
<article
id="contact"
className={`${styles.article} ${styles['article--no-comments']}`}
>
<PostHeader title={title} intro={intro} />
<div className={styles.body}>
<p>{t`All fields marked with * are required.`}</p>
{status && <p>{status}</p>}
<Form submitHandler={submitHandler}>
<FormItem>
<Input
id="contact-name"
name="name"
value={name}
setValue={setName}
label={t`Name`}
required={true}
/>
</FormItem>
<FormItem>
<Input
id="contact-email"
name="email"
value={email}
setValue={setEmail}
label={t`Email`}
required={true}
/>
</FormItem>
<FormItem>
<Input
id="contact-subject"
name="subject"
value={subject}
setValue={setSubject}
label={t`Subject`}
/>
</FormItem>
<FormItem>
<TextArea
id="contact-message"
name="message"
value={message}
setValue={setMessage}
label={t`Message`}
required={true}
/>
</FormItem>
<FormItem>
<ButtonSubmit>{t`Send`}</ButtonSubmit>
</FormItem>
</Form>
</div>
<Sidebar position="right">
<SocialMedia
title={t`Find me elsewhere`}
github={true}
gitlab={true}
linkedin={true}
/>
</Sidebar>
</article>
</>
);
};
ContactPage.getLayout = getLayout;
export const getStaticProps: GetStaticProps = async (
context: GetStaticPropsContext
) => {
const breadcrumbTitle = t`Contact`;
const { locale } = context;
const translation = await loadTranslation(locale || defaultLocale);
return {
props: {
breadcrumbTitle,
locale,
translation,
},
};
};
export default ContactPage;
|