Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add offer form and not so ready interview form #39

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
214 changes: 46 additions & 168 deletions src/components/JobApplicationDialog.jsx
Original file line number Diff line number Diff line change
@@ -1,90 +1,31 @@
import React, { useEffect, useState } from 'react';
import { useMutation } from '@apollo/client';
import CancelIcon from '@mui/icons-material/Cancel';
import SaveIcon from '@mui/icons-material/Save';
import Button from '@mui/material/Button';
import { ADD_JOB_APPLICATION, UPDATE_JOB_APPLICATION } from '../graphql/mutation';
import { GET_JOB_APPLICATIONS } from '../graphql/query';
import DialogTitleBar from './DialogTitleBar';
import React, { useState } from 'react';
import Tabs from '@mui/material/Tabs';
import Tab from '@mui/material/Tab';

import Dialog from '@mui/material/Dialog';
import DialogActions from '@mui/material/DialogActions';
import DialogContent from '@mui/material/DialogContent';

import FormControl from '@mui/material/FormControl';
import InputLabel from '@mui/material/InputLabel';
import MenuItem from '@mui/material/MenuItem';
import Select from '@mui/material/Select';
import TextField from '@mui/material/TextField';
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
import { DesktopDatePicker } from '@mui/x-date-pickers/DesktopDatePicker';
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
import dayjs from 'dayjs';
import DialogTitleBar from './DialogTitleBar';

export default function JobApplicationDialog({ jobApplication, handleClose, open, setOpen, isNew }) {
const [formData, setFormData] = useState({
companyName: '',
jobTitle: '',
salaryRange: '',
description: '',
jobUrl: '',
status: 'open',
appliedDate: dayjs().format('YYYY-MM-DD'),
});
import ApplicationForm from './forms/ApplicationForm';
import InterviewsForm from './forms/InterviewsForm';
import OfferForm from './forms/OfferForm';

const [dialogTitle, setDialogTitle] = useState('Edit Job Application');
const [newJobApplication] = useMutation(ADD_JOB_APPLICATION, {
refetchQueries: [{ query: GET_JOB_APPLICATIONS }],
});
const [updateJobApplication] = useMutation(UPDATE_JOB_APPLICATION, {
refetchQueries: [{ query: GET_JOB_APPLICATIONS }],
});

useEffect(() => {
if (isNew) {
setFormData({
...formData,
appliedDate: dayjs().format('YYYY-MM-DD'),
});
setDialogTitle('Add Job Application');
} else if (jobApplication) {
setFormData({
companyName: jobApplication.companyName || '',
jobTitle: jobApplication.jobTitle || '',
salaryRange: jobApplication.salaryRange || '',
description: jobApplication.description || '',
jobUrl: jobApplication.jobUrl || '',
status: jobApplication.status || 'open',
appliedDate: jobApplication.appliedDate || dayjs().format('YYYY-MM-DD'),
});
}
}, [open, jobApplication, isNew]);
export default function JobApplicationDialog({ jobApplication, handleClose, open, setOpen, isNew }) {

const handleFormChange = (e) => {
const { name, value } = e.target;
setFormData({
...formData,
[name]: value,
});
};
const [activeTab, setActiveTab] = useState(0);

const handleSubmit = (event) => {
event.preventDefault();
const mutationFn = isNew ? newJobApplication : updateJobApplication;
const variables = {
...formData,
...(jobApplication && { id: jobApplication.id }),
};
mutationFn({ variables });
setOpen(false);
const handleTabChange = (event, newValue) => {
setActiveTab(newValue);
};

return (
<Dialog
open={open}
onClose={handleClose}
aria-labelledby="modal-title"
aria-describedby="modal-description"
fullWidth
maxWidth="md"
height="lg"
slotProps={{
backdrop: {
sx: {
Expand All @@ -93,102 +34,39 @@ export default function JobApplicationDialog({ jobApplication, handleClose, open
},
}}
>
<DialogTitleBar title={dialogTitle} />
<form onSubmit={handleSubmit}>
<DialogContent dividers>
<TextField
required
id="companyName"
name="companyName"
label="Company Name"
fullWidth
variant="standard"
onChange={handleFormChange}
value={formData.companyName}
/>
<TextField
required
id="jobTitle"
name="jobTitle"
label="Job Title"
fullWidth
variant="standard"
onChange={handleFormChange}
value={formData.jobTitle}
/>
<TextField
id="salaryRange"
name="salaryRange"
label="Salary Range"
fullWidth
variant="standard"
onChange={handleFormChange}
value={formData.salaryRange}
/>

<DialogContent />
<LocalizationProvider dateAdapter={AdapterDayjs}>
<DesktopDatePicker
id="appliedDate"
label="Applied Date"
inputFormat="MM/DD/YYYY"
variant="standard"
value={formData.appliedDate}
onChange={(date) =>
setFormData({
...formData,
appliedDate: dayjs(date).format('YYYY-MM-DD'),
})
}
renderInput={(params) => <TextField {...params} />}
/>
</LocalizationProvider>

<TextField
id="description"
name="description"
label="Description"
multiline
rows={4}
fullWidth
variant="standard"
onChange={handleFormChange}
value={formData.description}
/>
<TextField
required
id="jobUrl"
name="jobUrl"
label="Job Link"
multiline
rows={4}
fullWidth
variant="standard"
onChange={handleFormChange}
value={formData.jobUrl}
/>
<DialogTitleBar title={(isNew ? 'Add ' : 'Edit ') + 'Job Application'} />
<Tabs
value={activeTab}
onChange={handleTabChange}
indicatorColor="primary"
textColor="primary"
variant="fullWidth"
>
<Tab label="Application" />
<Tab label="Interviews" />
<Tab label="Offer" />
</Tabs>
{activeTab === 0 && (
<ApplicationForm
jobApplication={jobApplication}
isNew={isNew}
setOpen={setOpen}
handleClose={handleClose}
/>
)}
{activeTab === 1 && (
<InterviewsForm
// jobApplicationId={jobApplication}
handleClose={handleClose}
/>
)}

<DialogContent />
<FormControl sx={{ minWidth: 120 }} variant="standard" size="small">
<InputLabel>Status</InputLabel>
<Select
name="status"
value={formData.status}
onChange={handleFormChange}
disabled={isNew}
>
<MenuItem value="open">open</MenuItem>
<MenuItem value="active">active</MenuItem>
<MenuItem value="rejected">rejected</MenuItem>
</Select>
</FormControl>

<DialogActions>
<Button color="info" variant="outlined" startIcon={<CancelIcon />} onClick={handleClose}>Cancel</Button>
<Button color="info" variant="contained" startIcon={<SaveIcon />} type="submit">Save</Button>
</DialogActions>
</DialogContent>
</form>
{activeTab === 2 && (
<OfferForm
jobApplicationId={parseInt(jobApplication.id)}
handleClose={handleClose}
/>
)}
</Dialog>
);
}
Loading
Loading