-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
97 lines (87 loc) · 2.55 KB
/
index.js
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
import { useState } from 'react';
import Head from 'next/head';
import Image from 'next/image';
import Button from '../components/formElements/Button';
import Input from '../components/formElements/Input';
import Textarea from '../components/formElements/Textarea';
import { updateUser } from '../utils/api';
export default function Home() {
const [loading, setloading] = useState(false);
const [error, setError] = useState(null);
const handleFormSubmit = async (e) => {
e.preventDefault();
const firstName = e.target.elements.firstName.value || '';
const lastName = e.target.elements.lastName.value || '';
const headline = e.target.elements.headline.value || '';
const location = e.target.elements.location.value || '';
const role = e.target.elements.role.value || '';
const apiData = {
firstName,
lastName,
headline,
location,
role,
};
try {
setloading(true);
await updateUser(apiData);
if (error) {
setError(null);
}
} catch (error) {
setError(error?.response?.data?.error?.message || 'Something went wrong');
} finally {
setloading(false);
}
};
return (
<>
<Head>
<title>Social Preview Demo</title>
<meta name='description' content='Generated by create next app' />
<link rel='icon' href='/favicon.ico' />
</Head>
<div className='h-screen w-screen bg-slate-200 flex justify-center items-center'>
<div className='bg-white w-2/5 border border-slate-400 p-4 rounded-md shadow-lg'>
<div className='flex justify-center mb-8'>
<Image
src='/images/peerlistLogo.svg'
width={140}
height={'100%'}
alt='peerlist logo'
/>
</div>
<form onSubmit={handleFormSubmit} className='mb-8'>
<div className='grid grid-cols-2 gap-4'>
<Input label='First Name' id='firstName' placeholder='Johnrao' />
<Input label='Last Name' id='lastName' placeholder='Doekar' />
</div>
<div className='my-4'>
<Textarea
label='Headline'
id='headline'
placeholder='Building Peerlist'
/>
</div>
<div className='grid grid-cols-2 gap-4 mb-4'>
<Input
label='Location'
id='location'
placeholder='Pune, MH, India'
/>
<Input label='Role' id='role' placeholder='Developer' />
</div>
<div className='flex justify-center'>
<Button loading={loading} type='submit'>
Save
</Button>
</div>
{error && (
<p className='text-sm mt-4 text-red-600 text-center'>{error}</p>
)}
</form>
</div>
</div>
</>
);
}