Skip to content

Commit

Permalink
EGCETSII#29-feat: integrate and use modal component
Browse files Browse the repository at this point in the history
  • Loading branch information
JSnow11 committed Dec 18, 2021
1 parent 03ca700 commit 05afcc1
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { UserTable } from "components/templates/users";
import { NewUserForm, UserTable } from "components/templates/users";

import Page from "../page";
import { userApi } from "api";
Expand Down Expand Up @@ -30,6 +30,7 @@ const UsersPage = () => {
return (
<Page title="Users">
<UserTable users={users || rows} />
<NewUserForm />
</Page>
);
};
Expand Down
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 };
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;

0 comments on commit 05afcc1

Please sign in to comment.