forked from EGCETSII/decide_django_2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EGCETSII#29-feat: integrate and use modal component
- Loading branch information
Showing
3 changed files
with
58 additions
and
3 deletions.
There are no files selected for viewing
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
5 changes: 3 additions & 2 deletions
5
decide/administration/frontend/src/components/templates/users/index.ts
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,3 +1,4 @@ | ||
import Component from "./userTable"; | ||
import UserTable from "./userTable"; | ||
import NewUserForm from "./newUserForm"; | ||
|
||
export { Component as UserTable }; | ||
export { NewUserForm, UserTable }; |
53 changes: 53 additions & 0 deletions
53
decide/administration/frontend/src/components/templates/users/newUserForm.tsx
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import React from "react"; | ||
import { SubmitHandler, useForm } from "react-hook-form"; | ||
import { userType } from "types"; | ||
import { ModalPage, Modal } from "components/02-molecules"; | ||
import { Add } from "@mui/icons-material"; | ||
import { FormItem } from "components/01-atoms/Input"; | ||
|
||
const Component = (props: { initialUser?: userType.User[] }) => { | ||
const { | ||
control, | ||
getValues, | ||
setError, | ||
formState: { errors }, | ||
} = useForm<{ username: string; username2: string }>(); | ||
|
||
const [sent, setSent] = React.useState(false); | ||
|
||
const onSubmitFailed = (e: any) => { | ||
console.log("error", e); | ||
setError("username", { type: "manual", message: "Fake Error" }); | ||
}; | ||
|
||
const onSubmit: SubmitHandler<{ username: string; username2: string }> = ( | ||
data | ||
) => { | ||
console.log("submit:", data); | ||
//Todo: call api and create user, | ||
//Todo: if created then close modal if not, call onSubmitFailed | ||
setSent(true); | ||
|
||
onSubmitFailed("not failed"); | ||
}; | ||
|
||
return ( | ||
<Modal | ||
onSubmit={() => onSubmit(getValues())} | ||
title="New User" | ||
openerIcon={<Add />} | ||
externalClose={sent} | ||
pages={[ | ||
<ModalPage description="Indique la información del Usuario"> | ||
<FormItem.TextInput | ||
control={control} | ||
name="username" | ||
error={errors.username?.message} | ||
></FormItem.TextInput> | ||
</ModalPage>, | ||
]} | ||
/> | ||
); | ||
}; | ||
|
||
export default Component; |