Reset form on submit
This commit is contained in:
@@ -30,6 +30,10 @@ interface Props {
|
|||||||
|
|
||||||
const STATUS_OPTIONS = ["Applied", "Waiting", "Interview", "Offer", "Rejected", "Ghosted"] as const;
|
const STATUS_OPTIONS = ["Applied", "Waiting", "Interview", "Offer", "Rejected", "Ghosted"] as const;
|
||||||
|
|
||||||
|
function getTodayIso() {
|
||||||
|
return new Date().toISOString().slice(0, 10);
|
||||||
|
}
|
||||||
|
|
||||||
export default function AddJobModal({ open, onClose, onCreated }: Props) {
|
export default function AddJobModal({ open, onClose, onCreated }: Props) {
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
@@ -45,7 +49,7 @@ export default function AddJobModal({ open, onClose, onCreated }: Props) {
|
|||||||
const [newCompanyLocation, setNewCompanyLocation] = useState("");
|
const [newCompanyLocation, setNewCompanyLocation] = useState("");
|
||||||
const [newCompanySource, setNewCompanySource] = useState("");
|
const [newCompanySource, setNewCompanySource] = useState("");
|
||||||
|
|
||||||
const [dateApplied, setDateApplied] = useState(() => new Date().toISOString().slice(0, 10));
|
const [dateApplied, setDateApplied] = useState(() => getTodayIso());
|
||||||
const [jobTitle, setJobTitle] = useState("");
|
const [jobTitle, setJobTitle] = useState("");
|
||||||
const [status, setStatus] = useState<(typeof STATUS_OPTIONS)[number]>("Applied");
|
const [status, setStatus] = useState<(typeof STATUS_OPTIONS)[number]>("Applied");
|
||||||
const [location, setLocation] = useState("");
|
const [location, setLocation] = useState("");
|
||||||
@@ -73,6 +77,32 @@ export default function AddJobModal({ open, onClose, onCreated }: Props) {
|
|||||||
setCompanies(cachedCompanies);
|
setCompanies(cachedCompanies);
|
||||||
}, [cachedCompanies]);
|
}, [cachedCompanies]);
|
||||||
|
|
||||||
|
const resetForm = () => {
|
||||||
|
setCompany(null);
|
||||||
|
setCompanyInput("");
|
||||||
|
setNewCompanyLocation("");
|
||||||
|
setNewCompanySource("");
|
||||||
|
setDateApplied(getTodayIso());
|
||||||
|
setJobTitle("");
|
||||||
|
setStatus("Applied");
|
||||||
|
setLocation("");
|
||||||
|
setSalary("");
|
||||||
|
setNextAction("");
|
||||||
|
setFollowUpAt("");
|
||||||
|
setJobUrl("");
|
||||||
|
setDeadline("");
|
||||||
|
setDescription("");
|
||||||
|
setTranslatedDescription("");
|
||||||
|
setDescriptionLanguage("");
|
||||||
|
setTags([]);
|
||||||
|
setNotes("");
|
||||||
|
setCoverLetter("");
|
||||||
|
setHasResume(false);
|
||||||
|
setHasCoverLetter(false);
|
||||||
|
setHasPortfolio(false);
|
||||||
|
setHasOtherAttachment(false);
|
||||||
|
};
|
||||||
|
|
||||||
const normalizedCompanyName = companyInput.trim();
|
const normalizedCompanyName = companyInput.trim();
|
||||||
const matchingCompany = useMemo(() => {
|
const matchingCompany = useMemo(() => {
|
||||||
if (!normalizedCompanyName) return null;
|
if (!normalizedCompanyName) return null;
|
||||||
@@ -179,6 +209,7 @@ export default function AddJobModal({ open, onClose, onCreated }: Props) {
|
|||||||
hasOtherAttachment,
|
hasOtherAttachment,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
resetForm();
|
||||||
onCreated();
|
onCreated();
|
||||||
onClose();
|
onClose();
|
||||||
toast("Job added.", "success");
|
toast("Job added.", "success");
|
||||||
|
|||||||
Reference in New Issue
Block a user