-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenter.page.tsx
62 lines (59 loc) · 2.05 KB
/
enter.page.tsx
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
import cn from 'classnames';
import React, { useEffect, useMemo, useState } from 'react';
import { NextSeo } from 'next-seo';
import { getRouteCanonical } from '../lib/route';
import EntryForm from '../components/entryForm';
import EntryDone from '../components/entryDone';
import { Entry, Route } from '../lib/types';
import { MESSAGE_MAX_LENGTH, STICKERS } from '../lib/constants';
export default function Enter() {
const metaUrl = useMemo(() => getRouteCanonical(Route.ENTER), []);
const [mainImageUrl, setMainImageUrl] = useState('');
const [message, setMessage] = useState('');
const [stickerIdx, setStickerIdx] = useState(-1);
const selectedSticker = STICKERS[stickerIdx];
const [name, setName] = useState('');
const [email, setEmail] = useState('');
const [remainingCharCount, setRemainingCharCount] =
useState(MESSAGE_MAX_LENGTH);
const [createdEntry, setCreatedEntry] = useState<Entry | null>(null);
const resetForm = () => {
setMainImageUrl('');
setMessage('');
setStickerIdx(-1);
setName('');
setEmail('');
setRemainingCharCount(MESSAGE_MAX_LENGTH);
setCreatedEntry(null);
};
useEffect(() => {
window.scrollTo(0, 0);
}, [createdEntry]);
return (
<>
<NextSeo canonical={metaUrl} openGraph={{ url: metaUrl }} />
<div className={cn('py-[50px] px-[15px] text-white', 'sm:px-[40px]')}>
{!createdEntry ? (
<EntryForm
mainImageUrl={mainImageUrl}
message={message}
remainingCharCount={remainingCharCount}
stickerIdx={stickerIdx}
selectedSticker={selectedSticker}
name={name}
email={email}
setMainImageUrl={setMainImageUrl}
setMessage={setMessage}
setRemainingCharCount={setRemainingCharCount}
setStickerIdx={setStickerIdx}
setName={setName}
setEmail={setEmail}
setCreatedEntry={setCreatedEntry}
/>
) : (
<EntryDone entry={createdEntry} resetForm={resetForm} />
)}
</div>
</>
);
}