Skip to content

Commit

Permalink
feat: implement submit talent patch form functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayobami6 committed Oct 25, 2023
1 parent 956bfa3 commit a375fdb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
21 changes: 18 additions & 3 deletions client/src/components/Modal/UpdateTalentModal.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import TButton from '../Button/TButton.tsx';
import { FaEdit } from 'react-icons/fa';
import { Dispatch, SetStateAction, useState } from 'react';
import { Dispatch, SetStateAction, useState, useContext } from 'react';
import { useDispatch } from 'react-redux';
import { TalentContext } from '../../pages/Talent/Talent.tsx';
import { talentPatch } from '../../actions/talent.ts';
import FileBase from 'react-file-base64';

interface Talent {
Expand Down Expand Up @@ -34,14 +37,26 @@ const UpdateTalentModal = ({
}: UpdateTalentModalProps): JSX.Element => {
const modalStyle = showTalentEditModal ? 'showModal' : '';
const [img, setImg] = useState('');
const tp = useContext(TalentContext);
const dispatch = useDispatch();

const handleSubmit = () => {};
const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
const formData = new FormData(e.target as HTMLFormElement);
formData.append('profileImg', img);
const data = Object.fromEntries(formData);
dispatch(talentPatch(talent._id, data));
tp.setRefresh(!tp.refresh);
const formElement = e.target as HTMLFormElement;
formElement.reset();
setShowTalentEditModal(false);
};

return (
<div className={'Modal ' + modalStyle}>
<div className='content'>
<div className={'header-11'}>
<h1>Add Education</h1>{' '}
<h1>Update Your Profile</h1>{' '}
<TButton value={'X'} onClick={() => setShowTalentEditModal(false)} />
</div>
<hr />
Expand Down
23 changes: 17 additions & 6 deletions client/src/pages/Talent/Talent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
import { createContext, useEffect, useState } from 'react';
import TalentNav from '../../components/Navbar/TalentNav';
import Loading from '../../components/Loading/Loading.tsx';

Check failure on line 5 in client/src/pages/Talent/Talent.tsx

View workflow job for this annotation

GitHub Actions / lint

'Loading' is defined but never used
import './Talent.css';
import { FaFile } from 'react-icons/fa';
import TButton from '../../components/Button/TButton';
Expand All @@ -25,7 +26,8 @@ import { getTalentEducations } from '../../api/education.ts';
import { getTalentCertifications } from '../../api/certifications.ts';
import { getTalentSkills } from '../../api/skills.ts';
import UpdateTalentModal from '../../components/Modal/UpdateTalentModal.tsx';

import { getTalent } from '../../actions/talent.ts';
import { useDispatch, useSelector } from 'react-redux';
// @ts-ignore
export const TalentContext: React.Context<{
refresh: boolean;
Expand All @@ -48,6 +50,9 @@ const Talent = (): JSX.Element => {
const [talentEducations, setTalentEducations] = useState([]);
const [talentSkills, setTalentSkills] = useState([]);
const [talentCertifications, setTalentCertifications] = useState([]);
const dispatch = useDispatch();
const [loading, setLoading] = useState();
const talent = useSelector((state) => state.talents.talent) || {};

useEffect(() => {
// @ts-ignore
Expand All @@ -62,7 +67,9 @@ const Talent = (): JSX.Element => {
getTalentCertifications(user._id).then((value) =>
setTalentCertifications(value.data),
);
dispatch(getTalent(setLoading, user._id));
}, [refresh, user._id]);

Check warning on line 71 in client/src/pages/Talent/Talent.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook useEffect has a missing dependency: 'dispatch'. Either include it or remove the dependency array
console.log(talent);
return (
<>
<TalentNav />
Expand All @@ -88,11 +95,15 @@ const Talent = (): JSX.Element => {
onClick={() => setShowTalentEditModal(true)}
/>
</div>
<UpdateTalentModal
showTalentEditModal={showTalentEditModal}
setShowTalentEditModal={setShowTalentEditModal}
talent={user}
/>
{loading ? (
''
) : (
<UpdateTalentModal
showTalentEditModal={showTalentEditModal}
setShowTalentEditModal={setShowTalentEditModal}
talent={talent}
/>
)}
</div>
</div>

Expand Down

0 comments on commit a375fdb

Please sign in to comment.