import React, {useEffect, useState} from "react"; import "../shared_css/Modal.css" import 'react-responsive-modal/styles.css'; import "./JobSeekerEditProfile.css" //Validation import * as yup from "yup"; import {yupResolver} from "@hookform/resolvers/yup"; import {Controller, useForm} from "react-hook-form"; import {useDispatch, useSelector} from "react-redux"; import {JobSeekerActions} from "../../redux/actions/JobSeekerActions"; import {notifyProfileEdit, notifyProfilePicChange} from "../../utils/toastUtils"; export const JobSeekerEditProfile = (props) => { const dispatch = useDispatch(); const auth = useSelector(state => state.auth.currentUser) const [seekerDetails, setSeekerDetails] = useState(null); const [profilePicFile, setProfilePicFile] = useState(null); let profilePicState = useSelector(state => state.images.profilePictures); const [profilePicPreview, setProfilePicPreview] = useState(null); const [profilePicView, setProfilePicView] = useState(null); useEffect(() => { if(auth) { dispatch(JobSeekerActions.fetchJobSeekerEditDetailsById(auth.id, (success, response) => { if(success) { setSeekerDetails(response.data); console.log(response.data) } })) } }, [auth]) useEffect(() => { if (auth.id) { if(!profilePicState[auth.id]) { dispatch(JobSeekerActions.downloadProfilePic(auth.id, (success, response) => { if (success) { setProfilePicView(response) //setDispatched(true) } })) //console.log("LOGO FETCH") } else { setProfilePicView(profilePicState[auth.id]) //console.log("LOGO STATE") } } }, [auth]) const schema = yup.object().shape({ email: yup.string().required("Please enter your email"), firstName: yup.string().required("Please enter your first name"), lastName: yup.string().required("Please enter your last name"), phoneNumber: yup.string().required("Please enter your phone number"), }) const {register, handleSubmit, formState: {errors}} = useForm({ resolver: yupResolver(schema), }); const editJobSeekerDetails = async (values) => { try { dispatch(JobSeekerActions.editJobSeekerDetailsById( { email: values.email, firstName: values.firstName, lastName: values.lastName, phoneNumber: values.phoneNumber, }, auth.id, (success, response) => { if (success) { // console.log("Recruiter details edited") notifyProfileEdit() setSeekerDetails(response.data) } } )) } catch (err) { console.error(err) } } const handleButtonClick = () => { document.getElementById('logo-upload-input').click(); }; const handleLogoChange = (event) => { const file = event.target.files[0]; if (file && (file.type === 'image/png' || file.type === 'image/jpeg')) { setProfilePicFile(file) setProfilePicPreview(URL.createObjectURL(file)); } event.target.value = null; }; const handleLogoUpload = async () => { try { const formData = new FormData(); formData.append("jobSeekerId", auth.id); formData.append("profilePicFile", profilePicFile); dispatch(JobSeekerActions.submitProfilePic(formData, (success, response) => { if (success) { // window.location.reload(); // MAYBE REMOVE // console.log("Logo uploaded successfully") notifyProfilePicChange() setProfilePicPreview(null) setProfilePicView(URL.createObjectURL(profilePicFile)) } })) } catch (error) { console.error(error) } } const handleCancelUpload = () => { setProfilePicFile(null) setProfilePicPreview(null) } return (
{profilePicPreview && (
)}
Company Banner {profilePicPreview ? <> : <> }
{seekerDetails &&

{seekerDetails.firstName + " " + seekerDetails.lastName}

} {/*

Active job listings: {activeJobListingsCount}

*/}
{seekerDetails && <>
Personal details

{errors.email?.message}

{errors.firstName?.message}

{errors.lastName?.message}

{errors.phoneNumber?.message}

}
) }