Advertisement
ptownhero

App.cs

Mar 17th, 2023
515
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import './App.css';
  2. import { useState } from 'react';
  3. import InputCV from './components/inputCV.js'
  4. import OutputCV from './components/outputCV.js'
  5.  
  6. export default function App() {
  7.     // States
  8.     const [introduction, setIntroduction] = useState({
  9.         firstName: '',
  10.         lastName: '',
  11.         phoneNumber: '',
  12.         email: '',
  13.         linkedIn: '',
  14.         website: '',
  15.     })
  16.    
  17.     const [summary, setSummary] = useState('');
  18.    
  19.     const [workHistory, setWorkHistory] = useState([{
  20.         id: 0,
  21.         jobName: '',
  22.         jobPosition: '',
  23.         startDate: '',
  24.         endDate: '',
  25.         jobDescription: ''
  26.     }]);
  27.    
  28.     const [educationHistory, setEducationHistory] = useState([{
  29.         id: 0,
  30.         educationName: '',
  31.         certificateName: '',
  32.         dateAcquired: '',
  33.         educationDescription: ''
  34.     }]);
  35.    
  36.     const [counters, setCounters] = useState([{
  37.         workHistory: 1,
  38.         educationHistory: 1
  39.     }])
  40.     // Helper Functions
  41.     const onIntroductionChange = (event, toUpdate) => {
  42.         let newIntroduction = introduction;
  43.         switch (toUpdate) {
  44.             case 'firstName':
  45.                 newIntroduction.firstName = event.target.value;
  46.                 break;
  47.             case 'lastName':
  48.                 newIntroduction.lastName = event.target.value;
  49.                 break;
  50.             case 'phoneNumber':
  51.                 newIntroduction.phoneNumber = event.target.value;
  52.                 break;
  53.             case 'email':
  54.                 newIntroduction.email = event.target.value;
  55.                 break;
  56.             case 'linkedIn':
  57.                 newIntroduction.linkedIn = event.target.value;
  58.                 break;
  59.             case 'website':
  60.                 newIntroduction.website = event.target.value;
  61.                 break;
  62.             default:
  63.                 throw new Error("There's something wrong with onIntroductionChange()");
  64.         }
  65.         return newIntroduction
  66.     }
  67.  
  68.     const onWorkHistoryChange = (event, toUpdate, index) => {
  69.         let newWorkHistory = workHistory;
  70.         switch (toUpdate) {
  71.             case 'jobName':
  72.                 newWorkHistory[index].jobName = event.target.value;
  73.                 break;
  74.             case 'jobPosition':
  75.                 newWorkHistory[index].jobPosition = event.target.value;
  76.                 break;
  77.             case 'startDate':
  78.                 newWorkHistory[index].startDate = event.target.value;
  79.                 break;
  80.             case 'endDate':
  81.                 newWorkHistory[index].endDate = event.target.value;
  82.                 break;
  83.             case 'jobDescription':
  84.                 newWorkHistory[index].jobDescription = event.target.value;
  85.                 break;
  86.             default:
  87.                 throw new Error("There's something wrong with onWorkHistoryChange()");
  88.         }
  89.         return newWorkHistory;
  90.     }
  91.  
  92.     const onEducationChange = (event, toUpdate, index) => {
  93.         let newEducationHistory = educationHistory;
  94.         switch (toUpdate) {
  95.             case 'educationName':
  96.                 newEducationHistory[index].educationName = event.target.value;
  97.                 break;
  98.             case 'certificateName':
  99.                 newEducationHistory[index].certificateName = event.target.value;
  100.                 break;
  101.             case 'dateAcquired':
  102.                 newEducationHistory[index].dateAcquired = event.target.value;
  103.                 break;
  104.             case 'educationDescription':
  105.                 newEducationHistory[index].educationDescription = event.target.value;
  106.                 break;
  107.             default:
  108.                 throw new Error("There's something wrong with onEducationChange()");
  109.         }
  110.         return newEducationHistory;
  111.     }
  112.  
  113.     return (
  114.         <div className="App">
  115.             <Header />
  116.             <InputCV
  117.                 counter={counters}
  118.                 setCounter={setCounters}
  119.                 setIntroduction={setIntroduction}
  120.                 onIntroductionChange={onIntroductionChange}
  121.                 onWorkHistoryChange={onWorkHistoryChange}
  122.                 onEducationChange={onEducationChange}
  123.                 summary={summary}
  124.                 setSummary={setSummary}
  125.                 />
  126.             <OutputCV
  127.                 introduction={introduction}
  128.                 summary={summary}
  129.                 workHistory={workHistory}
  130.                 educationHistory={educationHistory}
  131.             />
  132.         </div>
  133.     );
  134. }
  135.  
  136. function Header() {
  137.     return (
  138.         <header>
  139.             <h1>Simple-CV</h1>
  140.         </header>
  141.     )
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement