Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import {
- CreateAccountContainer,
- FormContainer,
- Form,
- Box,
- Button,
- Input,
- Label
- } from '../styles/pages/createAccount.styles';
- import React, { useState, useEffect } from 'react';
- import api from '../api';
- export default function CreateAccount() {
- const [userCreate, setUserCreate] = useState([]);
- const [formData, setFormData] = useState({
- firstName: "",
- lastName: "",
- emailAddress: "",
- phoneNumber: "",
- password: "",
- dateOfBirth: ""
- });
- const fetchUserCreation = async () => {
- const response = await api.get("/create_account");
- setUserCreate(response.data);
- };
- useEffect(() => {
- fetchUserCreation();
- }, []);
- const handleFormSubmit = async (event) => {
- event.preventDefault();
- await api.post("/create_account", formData);
- fetchUserCreation();
- setFormData({
- firstName: "",
- lastName: "",
- emailAddress: "",
- phoneNumber: "",
- password: "",
- dateOfBirth: ""
- });
- };
- const handleInputChange = async (event) => {
- const value = event.target.type === "checkbox" ? event.target.checked : event.target.value;
- setFormData({
- ...formData,
- [event.target.name]: value,
- });
- };
- return (
- <CreateAccountContainer className="container-fluid">
- <FormContainer className="container">
- <Form onSubmit={handleFormSubmit}>
- <Box className="mb-3 mt-3">
- <Label htmlFor="first_name" className="form-label">First Name</Label>
- <Input type="text"
- className="form-control"
- id="first_name"
- name="first_name"
- onChange={handleInputChange}
- value={FormData.firstName} />
- </Box>
- <Box className="mb-3">
- <Label htmlFor="last_name" className="form-label">Last Name</Label>
- <Input type="text"
- className="form-control"
- id="last_name"
- name="last_name"
- onChange={handleInputChange}
- value={FormData.lastName} />
- </Box>
- <Box className="mb-3">
- <Label htmlFor="email_address" className="form-label">Email Address</Label>
- <Input type="email"
- className="form-control"
- placeholder="[email protected]"
- id="email_address"
- name="email_address"
- onChange={handleInputChange}
- value={FormData.emailAddress} />
- </Box>
- <Box className="mb-3">
- <Label htmlFor="phone_number" className="form-label">Phone Number</Label>
- <Input type="tel"
- className="form-control"
- id="phone_number"
- name="phone_number"
- placeholder="(999) 999-9999"
- onChange={handleInputChange}
- value={FormData.phoneNumber} />
- </Box>
- <Box className="mb-3">
- <Label htmlFor="create_password" className="form-label">Create Password</Label>
- <Input type="text"
- className="form-control"
- id="create_password"
- name="create_password"
- onChange={handleInputChange}
- value={FormData.password} />
- </Box>
- <Box className="mb-3">
- <Label htmlFor="confirm_password" className="form-label">Confirm Password</Label>
- <Input type="text"
- className="form-control"
- id="confirm_password"
- name="confirm_password"
- onChange={handleInputChange}
- value={FormData.password} />
- </Box>
- <Box className="mb-3">
- <Label htmlFor="dob" className="form-label">Date Of Birth</Label>
- <Input type="date"
- className="form-control"
- id="date"
- name="date"
- onChange={handleInputChange}
- value={FormData.dateOfBirth} />
- </Box>
- <Button type="submit" className="btn">Create Account</Button>
- </Form>
- </FormContainer>
- </CreateAccountContainer>
- );
- };
Advertisement
Add Comment
Please, Sign In to add comment