@@ -16,7 +16,7 @@ import CircleIcon from '@mui/icons-material/Circle';
1616import CircleOutlinedIcon from '@mui/icons-material/CircleOutlined' ;
1717import { Formik , Form , Field } from 'formik' ;
1818import * as Yup from 'yup' ;
19-
19+ import axios from 'axios' ;
2020
2121// CHANGED: Props now include the siteId.
2222interface Props {
@@ -174,7 +174,7 @@ function PersonalInfo({ onSubmit, setIsFormValid }: PersonalInfoProps) {
174174 validationSchema = { validationSchema }
175175 validateOnChange = { false }
176176 validateOnBlur = { false }
177- onSubmit = { onSubmit }
177+ onSubmit = { ( values ) => onSubmit ( values ) }
178178 >
179179 { ( {
180180 values,
@@ -468,16 +468,26 @@ function TermsAndConditions({
468468
469469export default function SignUpPage ( { setShowSignUp, siteID } : Props ) {
470470
471+ const navigate = useNavigate ( ) ;
472+
471473 const [ isChecked , setIsChecked ] = useState (
472474 new Array ( termsAndConditionsCheckboxesMap . length ) . fill ( false ) ,
473475 ) ;
474- const [ isFormValid , setIsFormValid ] = useState ( false ) ; // Track form validity
475-
476- const navigate = useNavigate ( ) ;
476+ const [ isFormValid , setIsFormValid ] = useState ( false ) ; // Track form validity
477+ const [ formValues , setFormValues ] = useState ( {
478+ firstname : "" ,
479+ lastname : "" ,
480+ email : "" ,
481+ phone : "" ,
482+ birthyear : "" ,
483+ groupRepresentative : false ,
484+ groupMembers : "" ,
485+ } )
477486 const [ step , setStep ] = useState ( 1 ) ;
478487
479- const handleNext = ( ) => {
488+ const handleNext = ( values : any ) => {
480489 if ( step < 2 ) setStep ( step + 1 ) ;
490+ setFormValues ( values ) ;
481491 } ;
482492
483493 const handleBack = ( ) => {
@@ -488,10 +498,48 @@ export default function SignUpPage({ setShowSignUp, siteID }: Props) {
488498 setShowSignUp ( false ) ;
489499 } ;
490500
491- const handleSubmit = ( ) => {
492- if ( isChecked . every ( Boolean ) ) {
493- console . log ( "Submitting application for siteID:" , siteID ) ;
494- navigate ( '/success' ) ;
501+ const handleSubmit = async ( ) => {
502+ if ( isChecked . every ( Boolean ) && isFormValid ) {
503+ const userRequestBody = {
504+
505+ } ;
506+
507+ try {
508+ const now = new Date ( ) . toISOString ( ) ;
509+ const names = [ ]
510+ if ( formValues [ "groupRepresentative" ] ) {
511+ const groupMembers = formValues [ "groupMembers" ] . split ( "," )
512+ names . push ( ...groupMembers )
513+ }
514+
515+ const applicationRequestBody = {
516+ firstName : formValues [ "firstname" ] ,
517+ lastName : formValues [ "lastname" ] ,
518+ phoneNumber : formValues [ "phone" ] ,
519+ email : formValues [ "email" ] ,
520+ zipCode : "123" ,
521+ birthDate : formValues [ "birthyear" ] ,
522+ siteId : siteID ,
523+ names : names ,
524+ status : "Pending" ,
525+ dateApplied : now ,
526+ isFirstApplication : true ,
527+ } ;
528+
529+ const applicationResponse = await axios . post (
530+ `${ import . meta. env . VITE_API_BASE_URL } /applications` ,
531+ applicationRequestBody ,
532+ {
533+ headers : {
534+ 'Content-Type' : 'application/json'
535+ } }
536+ ) ;
537+
538+ navigate ( '/success' ) ;
539+
540+ } catch ( error ) {
541+ console . error ( "Error:" , error ) ;
542+ }
495543 }
496544} ;
497545
0 commit comments