-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved around some files to more appropriate places. (#208)
* Deleted unnecessary files and moved contents to more appropriate space. * Prevent form from clearing after an error. Move types to table file.
- Loading branch information
Showing
8 changed files
with
186 additions
and
209 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,70 @@ | ||
import { trpc } from "@/client/lib/trpc"; | ||
import React from "react"; | ||
import MyParas from "@/components/myParas/MyParas"; | ||
import PersonTable, { Para, ParaHeadCell } from "@/components/table/table"; | ||
|
||
function Staff() { | ||
return <MyParas />; | ||
} | ||
const Staff = () => { | ||
const utils = trpc.useContext(); | ||
const { data: paras, isLoading } = trpc.case_manager.getMyParas.useQuery(); | ||
|
||
const createPara = trpc.para.createPara.useMutation({ | ||
onSuccess: async (data) => { | ||
await assignParaToCaseManager.mutateAsync({ | ||
para_id: data?.user_id as string, | ||
}); | ||
}, | ||
}); | ||
|
||
const assignParaToCaseManager = trpc.case_manager.addPara.useMutation({ | ||
onSuccess: () => utils.case_manager.getMyParas.invalidate(), | ||
}); | ||
|
||
const handleSubmit = async (event: React.FormEvent<HTMLFormElement>) => { | ||
event.preventDefault(); | ||
const data = new FormData(event.currentTarget); | ||
|
||
try { | ||
await createPara.mutateAsync({ | ||
first_name: data.get("first_name") as string, | ||
last_name: data.get("last_name") as string, | ||
email: data.get("email") as string, | ||
}); | ||
// resetting the form this way is only necessary if the form remains visible upon adding a person. due to Materials UI, the reset form(s) will show as "touched" (TT). | ||
(event.target as HTMLFormElement).reset(); | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
}; | ||
|
||
if (isLoading) { | ||
return <div>Loading...</div>; | ||
} | ||
|
||
const headCells: ParaHeadCell[] = [ | ||
{ | ||
id: "first_name", | ||
label: "First Name", | ||
hasInput: true, | ||
}, | ||
{ | ||
id: "last_name", | ||
label: "Last Name", | ||
hasInput: true, | ||
}, | ||
{ | ||
id: "email", | ||
label: "Email", | ||
hasInput: true, | ||
}, | ||
]; | ||
|
||
return ( | ||
<PersonTable | ||
people={paras as Para[]} | ||
onSubmit={handleSubmit} | ||
headCells={headCells} | ||
type="Staff" | ||
/> | ||
); | ||
}; | ||
|
||
export default Staff; |
Oops, something went wrong.