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;
|
||||
|
||||
function getTodayIso() {
|
||||
return new Date().toISOString().slice(0, 10);
|
||||
}
|
||||
|
||||
export default function AddJobModal({ open, onClose, onCreated }: Props) {
|
||||
const { toast } = useToast();
|
||||
const { t } = useI18n();
|
||||
@@ -45,7 +49,7 @@ export default function AddJobModal({ open, onClose, onCreated }: Props) {
|
||||
const [newCompanyLocation, setNewCompanyLocation] = 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 [status, setStatus] = useState<(typeof STATUS_OPTIONS)[number]>("Applied");
|
||||
const [location, setLocation] = useState("");
|
||||
@@ -73,6 +77,32 @@ export default function AddJobModal({ open, onClose, onCreated }: Props) {
|
||||
setCompanies(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 matchingCompany = useMemo(() => {
|
||||
if (!normalizedCompanyName) return null;
|
||||
@@ -179,6 +209,7 @@ export default function AddJobModal({ open, onClose, onCreated }: Props) {
|
||||
hasOtherAttachment,
|
||||
});
|
||||
|
||||
resetForm();
|
||||
onCreated();
|
||||
onClose();
|
||||
toast("Job added.", "success");
|
||||
|
||||
Reference in New Issue
Block a user