mekasu0124

Untitled

Oct 21st, 2023
463
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import {
  2.   CreateAccountContainer,
  3.   FormContainer,
  4.   Form,
  5.   Box,
  6.   Button,
  7.   Input,
  8.   Label
  9. } from '../styles/pages/createAccount.styles';
  10. import React, { useState, useEffect } from 'react';
  11. import api from '../api';
  12.  
  13. export default function CreateAccount() {
  14.   const [userCreate, setUserCreate] = useState([]);
  15.   const [formData, setFormData] = useState({
  16.     firstName: "",
  17.     lastName: "",
  18.     emailAddress: "",
  19.     phoneNumber: "",
  20.     password: "",
  21.     dateOfBirth: ""
  22.   });
  23.  
  24.   const fetchUserCreation = async () => {
  25.     const response = await api.get("/create_account");
  26.     setUserCreate(response.data);
  27.   };
  28.  
  29.   useEffect(() => {
  30.     fetchUserCreation();
  31.   }, []);
  32.  
  33.   const handleFormSubmit = async (event) => {
  34.     event.preventDefault();
  35.  
  36.     await api.post("/create_account", formData);
  37.     fetchUserCreation();
  38.     setFormData({
  39.       firstName: "",
  40.       lastName: "",
  41.       emailAddress: "",
  42.       phoneNumber: "",
  43.       password: "",
  44.       dateOfBirth: ""
  45.     });
  46.   };
  47.  
  48.   const handleInputChange = async (event) => {
  49.     const value = event.target.type === "checkbox" ? event.target.checked : event.target.value;
  50.     setFormData({
  51.       ...formData,
  52.       [event.target.name]: value,
  53.     });
  54.   };
  55.  
  56.   return (
  57.     <CreateAccountContainer className="container-fluid">
  58.       <FormContainer className="container">
  59.         <Form onSubmit={handleFormSubmit}>
  60.           <Box className="mb-3 mt-3">
  61.             <Label htmlFor="first_name" className="form-label">First Name</Label>
  62.             <Input type="text"
  63.                    className="form-control"
  64.                    id="first_name"
  65.                    name="first_name"
  66.                    onChange={handleInputChange}
  67.                    value={FormData.firstName} />
  68.           </Box>
  69.  
  70.           <Box className="mb-3">
  71.             <Label htmlFor="last_name" className="form-label">Last Name</Label>
  72.             <Input type="text"
  73.                    className="form-control"
  74.                    id="last_name"
  75.                    name="last_name"
  76.                    onChange={handleInputChange}
  77.                    value={FormData.lastName} />
  78.           </Box>
  79.  
  80.           <Box className="mb-3">
  81.             <Label htmlFor="email_address" className="form-label">Email Address</Label>
  82.             <Input type="email"
  83.                    className="form-control"
  84.                    placeholder="[email protected]"
  85.                    id="email_address"
  86.                    name="email_address"
  87.                    onChange={handleInputChange}
  88.                    value={FormData.emailAddress} />
  89.           </Box>
  90.  
  91.           <Box className="mb-3">
  92.             <Label htmlFor="phone_number" className="form-label">Phone Number</Label>
  93.             <Input type="tel"
  94.                    className="form-control"
  95.                    id="phone_number"
  96.                    name="phone_number"
  97.                    placeholder="(999) 999-9999"
  98.                    onChange={handleInputChange}
  99.                    value={FormData.phoneNumber} />
  100.           </Box>
  101.  
  102.           <Box className="mb-3">
  103.             <Label htmlFor="create_password" className="form-label">Create Password</Label>
  104.             <Input type="text"
  105.                     className="form-control"
  106.                     id="create_password"
  107.                     name="create_password"
  108.                     onChange={handleInputChange}
  109.                     value={FormData.password} />
  110.           </Box>
  111.  
  112.           <Box className="mb-3">
  113.             <Label htmlFor="confirm_password" className="form-label">Confirm Password</Label>
  114.             <Input type="text"
  115.                     className="form-control"
  116.                     id="confirm_password"
  117.                     name="confirm_password"
  118.                     onChange={handleInputChange}
  119.                     value={FormData.password} />
  120.           </Box>
  121.  
  122.           <Box className="mb-3">
  123.             <Label htmlFor="dob" className="form-label">Date Of Birth</Label>
  124.             <Input type="date"
  125.                    className="form-control"
  126.                    id="date"
  127.                    name="date"
  128.                    onChange={handleInputChange}
  129.                    value={FormData.dateOfBirth} />
  130.           </Box>
  131.  
  132.           <Button type="submit" className="btn">Create Account</Button>
  133.         </Form>
  134.       </FormContainer>
  135.     </CreateAccountContainer>
  136.   );
  137. };
Advertisement
Add Comment
Please, Sign In to add comment