From d0e6a43a01031eb3f2d18a998bdb431b58ed2a7f Mon Sep 17 00:00:00 2001 From: pauladamseniii Date: Tue, 17 Oct 2023 23:34:33 -0400 Subject: [PATCH] Finish UI --- src/components/Contexts/CarUpdatesContext.jsx | 13 ++ .../Contexts/__mocks__/CarUpdatesContext.jsx | 1 + src/components/Routes/SiteRoutes.jsx | 10 ++ src/components/SUMS/Add/index.jsx | 120 ++++++++++++++++++ src/components/SUMS/index.jsx | 37 +++++- src/services/updatesAPI.js | 14 +- 6 files changed, 187 insertions(+), 8 deletions(-) create mode 100644 src/components/SUMS/Add/index.jsx diff --git a/src/components/Contexts/CarUpdatesContext.jsx b/src/components/Contexts/CarUpdatesContext.jsx index 2227dc5..fb720f3 100644 --- a/src/components/Contexts/CarUpdatesContext.jsx +++ b/src/components/Contexts/CarUpdatesContext.jsx @@ -342,6 +342,18 @@ export const CarUpdatesProvider = ({ children }) => { return result; }; + const addSUMSVersionRxSwins = async (sums_version, data, token) => { + try { + setBusy(true); + const result = await api.addSUMSVersionRxSwins(sums_version, data, token); + if (result.error) + throw new Error(`Add software version rxswin error. ${result.message}`); + return result; + } finally { + setBusy(false); + } + }; + return ( { updateSUMSVersion, getSUMSVersionRxSwins, deleteSUMSVersionRxSwins, + addSUMSVersionRxSwins, }} > {children} diff --git a/src/components/Contexts/__mocks__/CarUpdatesContext.jsx b/src/components/Contexts/__mocks__/CarUpdatesContext.jsx index 0477b75..c83c7c2 100644 --- a/src/components/Contexts/__mocks__/CarUpdatesContext.jsx +++ b/src/components/Contexts/__mocks__/CarUpdatesContext.jsx @@ -155,5 +155,6 @@ export const useCarUpdatesContext = () => ({ getSUMSVersions: jest.fn(() => sumsVersions), getSUMSVersionRxSwins: jest.fn(() => sumsVersionRxSwins), deleteSUMSVersionRxSwins: jest.fn(), + addSUMSVersionRxSwins: jest.fn(), updateSUMSVersion: jest.fn(), }); \ No newline at end of file diff --git a/src/components/Routes/SiteRoutes.jsx b/src/components/Routes/SiteRoutes.jsx index 5849252..ed31bb0 100644 --- a/src/components/Routes/SiteRoutes.jsx +++ b/src/components/Routes/SiteRoutes.jsx @@ -42,6 +42,7 @@ const SuppliersList = React.lazy(() => import("../Suppliers/List")); const SupplierDetails = React.lazy(() => import("../Suppliers/Details")); const Datascope = React.lazy(() => import("../Dashboard")); const SumsRxSwin = React.lazy(() => import("../SUMS")); +const SumsRxSwinAdd = React.lazy(() => import("../SUMS/Add")); const DashboardCustom = React.lazy(() => import("../DashboardCustom")); const SiteRoutes = () => { @@ -315,6 +316,15 @@ const SiteRoutes = () => { rolesPerGroup={Permissions.FiskerMagnaCreate} providers={providers} /> + } + type={TYPES.PROTECTED} + token={token} + groups={groups} + rolesPerGroup={Permissions.FiskerMagnaCreate} + providers={providers} + /> diff --git a/src/components/SUMS/Add/index.jsx b/src/components/SUMS/Add/index.jsx new file mode 100644 index 0000000..2ea14b9 --- /dev/null +++ b/src/components/SUMS/Add/index.jsx @@ -0,0 +1,120 @@ +import { + Button, + TextField +} from "@material-ui/core"; +import { useParams } from "react-router"; +import React, { useEffect, useState } from "react"; +import { Redirect } from "react-router"; +import { logger } from "../../../services/monitoring"; +import { useStatusContext } from "../../Contexts/StatusContext"; +import { + CarUpdatesProvider, + useCarUpdatesContext +} from "../../Contexts/CarUpdatesContext"; +import { useUserContext } from "../../Contexts/UserContext"; +import useStyles from "../../useStyles"; + +const MainForm = () => { + const { addSUMSVersionRxSwins, busy } = useCarUpdatesContext(); + const { + token: { + idToken: { jwtToken: token }, + }, + } = useUserContext(); + const classes = useStyles(); + const [redirect, setRedirect] = useState(null); + const { sums_version } = useParams(); + const { setMessage, setTitle, setSitePath } = useStatusContext(); + const [rxswin, setRxswin] = useState(""); + + useEffect(() => { + setTitle(`Add RXSWIN to SUMS Version ${sums_version}`); + setSitePath([ + { + label: `SUMS Version ${sums_version}`, + link: `/sums/${sums_version}`, + }, + { + label: `SUMS Version ${sums_version}`, + link: `/sums-rxswin-add/${sums_version}`, + }, + { + label: `Add RXSWIN`, + }, + ]); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []); + + const onRxswinChange = (event) => { + setRxswin(event.target.value); + } + + const onSubmit = async (event) => { + try { + event.preventDefault(); + + const data = { + "swversion_rxswins": [ + { + "version": sums_version, + "rxswin": rxswin, + }, + ], + }; + + const result = await addSUMSVersionRxSwins(sums_version, data, token); + if (!result || result.error) return; + + setMessage(`Added ${rxswin}`); + setRedirect(`/sums/${sums_version}`); + } catch (e) { + setMessage(e.message); + logger.warn(e.stack); + } + }; + + if (redirect && redirect.length > 0) { + return ; + } + + return ( +
+
+ + + +
+ ); +}; + +const SumsRxSwinAdd = () => ( + + + +); + +export default SumsRxSwinAdd; \ No newline at end of file diff --git a/src/components/SUMS/index.jsx b/src/components/SUMS/index.jsx index ff7e4cf..b8efb42 100644 --- a/src/components/SUMS/index.jsx +++ b/src/components/SUMS/index.jsx @@ -1,4 +1,5 @@ import { + Grid, IconButton, Table, TableBody, @@ -7,7 +8,10 @@ import { TablePagination, TableRow, } from "@material-ui/core"; +import AddCircleIcon from "@material-ui/icons/AddCircle"; import DeleteIcon from "@material-ui/icons/Delete"; +import clsx from "clsx"; +import { LocalDateTimeString } from "../../utils/dates"; import { logger } from "../../services/monitoring"; import React, { useEffect, useState } from "react"; import { useParams } from "react-router"; @@ -17,6 +21,7 @@ import { } from "../Contexts/CarUpdatesContext"; import { useStatusContext } from "../Contexts/StatusContext"; import { useUserContext } from "../Contexts/UserContext"; +import { Link } from "react-router-dom"; import TableHeaderSortable from "../Table/HeaderSortable"; import { useLocalStorage } from "../useLocalStorage"; import DeleteConfirmation from "../DeleteConfirmation"; @@ -26,12 +31,12 @@ import { RoleWrap } from "../Controls/RoleWrap"; const tableColumns = [ { - id: "sums_version", - label: "SUMS Version", + id: "sums_rxswin", + label: "RXSWIN (RX Software Identification Number)", }, { - id: "sums_rxswin", - label: "RXSwin Version", + id: "created_at", + label: "Created", }, ]; @@ -59,7 +64,18 @@ const MainForm = () => { groups, providers, } = useUserContext(); - const { setMessage } = useStatusContext(); + const { setMessage, setTitle, setSitePath } = useStatusContext(); + + useEffect(() => { + setTitle(`SUMS Version ${sums_version}`); + setSitePath([ + { + label: `SUMS Version ${sums_version}`, + link: `/sums/${sums_version}`, + }, + ]); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []); useEffect(() => { (async () => { @@ -122,6 +138,13 @@ const MainForm = () => { return (
+ + + + + + + { {versionRxSwins.map((row, index) => ( - {row.version} + {row.rxswin} - {row.rxswin} + {LocalDateTimeString(row.created)} + fetch(`${API_ENDPOINT}/manifest/sums/${sums_version}/rxswins`, { + method: "POST", + headers: Object.assign( + { "Content-Type": "application/json" }, + getAuthHeaderOptions(token) + ), + body: JSON.stringify(data), + }) + .then(fetchRespHandler) + .catch(errorHandler), }; export default updatesAPI; \ No newline at end of file