diff --git a/typescript/Frontend/src/components/Users/AddUser.tsx b/typescript/Frontend/src/components/Users/AddUser.tsx index de7182310..8d50ad04f 100644 --- a/typescript/Frontend/src/components/Users/AddUser.tsx +++ b/typescript/Frontend/src/components/Users/AddUser.tsx @@ -1,6 +1,6 @@ import { Dialog, DialogTitle, IconButton, DialogContent } from "@mui/material"; import { useState } from "react"; -import { FormattedMessage } from "react-intl"; +import { FormattedMessage, useIntl } from "react-intl"; import axiosConfig from "../../config/axiosConfig"; import { I_User } from "../../util/user.util"; import InnovenergyButton from "../Layout/InnovenergyButton"; @@ -9,12 +9,15 @@ import UserForm from "./UserForm"; const AddUser = () => { const [open, setOpen] = useState(false); + const { locale } = useIntl(); const handleSubmit = (data: Partial) => { - return axiosConfig.post("/CreateUser", data).then((res) => { - setOpen(false); - return res; - }); + return axiosConfig + .post("/CreateUser", { ...data, password: "", language: locale }) + .then((res) => { + setOpen(false); + return res; + }); }; return ( diff --git a/typescript/Frontend/src/components/Users/User.tsx b/typescript/Frontend/src/components/Users/User.tsx index 065e6a2b6..811704372 100644 --- a/typescript/Frontend/src/components/Users/User.tsx +++ b/typescript/Frontend/src/components/Users/User.tsx @@ -1,16 +1,18 @@ import { Box, CircularProgress, Alert } from "@mui/material"; import { AxiosError } from "axios"; -import { useState, useEffect, FC } from "react"; +import { useState, useEffect } from "react"; import { useParams } from "react-router-dom"; import axiosConfig from "../../config/axiosConfig"; import { I_User } from "../../util/user.util"; import UserForm from "./UserForm"; +import { useIntl } from "react-intl"; interface I_DetailProps { hasMoveButton?: boolean; } const Detail = (props: I_DetailProps) => { const { id } = useParams(); + const { locale } = useIntl(); const [values, setValues] = useState(); const [loading, setLoading] = useState(false); const [error, setError] = useState(); @@ -20,10 +22,12 @@ const Detail = (props: I_DetailProps) => { axiosConfig .get("/GetUserById?id=" + id) .then((res) => { + console.log("noterr"); setValues(res.data); setLoading(false); }) .catch((err: AxiosError) => { + console.log("err"); setError(err); setLoading(false); }); @@ -33,6 +37,8 @@ const Detail = (props: I_DetailProps) => { return axiosConfig.put("/UpdateUser", { ...formikValues, id: id, + password: "", + language: locale, }); }; diff --git a/typescript/Frontend/src/components/Users/UserForm.tsx b/typescript/Frontend/src/components/Users/UserForm.tsx index c0b9474b9..5474ca3fb 100644 --- a/typescript/Frontend/src/components/Users/UserForm.tsx +++ b/typescript/Frontend/src/components/Users/UserForm.tsx @@ -1,5 +1,5 @@ -import { Alert, Grid, Snackbar } from "@mui/material"; -import { AxiosResponse } from "axios"; +import { Alert, CircularProgress, Grid, Snackbar } from "@mui/material"; +import { AxiosError, AxiosResponse } from "axios"; import { useFormik } from "formik"; import { useState } from "react"; import { FormattedMessage, useIntl } from "react-intl"; @@ -14,6 +14,8 @@ interface I_UserFormProps { const UserForm = (props: I_UserFormProps) => { const { values, handleSubmit } = props; const [open, setOpen] = useState(false); + const [loading, setLoading] = useState(false); + const [error, setError] = useState(); const intl = useIntl(); @@ -21,11 +23,19 @@ const UserForm = (props: I_UserFormProps) => { initialValues: { email: values ? values.email : "", information: values ? values.information : "", + name: values ? values.name : "", }, onSubmit: (formikValues) => { - handleSubmit(formikValues).then(() => { - setOpen(true); - }); + setLoading(true); + handleSubmit(formikValues) + .then(() => { + setOpen(true); + }) + .catch((err: AxiosError) => { + setOpen(true); + setError(err); + setLoading(false); + }); }, }); @@ -37,6 +47,16 @@ const UserForm = (props: I_UserFormProps) => {
+ { handleChange={formik.handleChange} /> { handleChange={formik.handleChange} /> + {loading && } - + { autoHideDuration={6000} onClose={handleClose} > - - + + {/* TODO how to handle err translation? */} + {error ? ( + + ) : ( + + )}