diff --git a/packages/rmw-shell/package-lock.json b/packages/rmw-shell/package-lock.json index 6c296362..45037081 100644 --- a/packages/rmw-shell/package-lock.json +++ b/packages/rmw-shell/package-lock.json @@ -1,12 +1,12 @@ { "name": "rmw-shell", - "version": "11.2.24", + "version": "11.2.25", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "rmw-shell", - "version": "11.2.24", + "version": "11.2.25", "license": "MIT", "devDependencies": { "@emotion/react": "^11.10.4", diff --git a/packages/rmw-shell/package.json b/packages/rmw-shell/package.json index 9c9260e1..42544bc7 100644 --- a/packages/rmw-shell/package.json +++ b/packages/rmw-shell/package.json @@ -1,6 +1,6 @@ { "name": "rmw-shell", - "version": "11.2.24", + "version": "11.2.25", "description": "React template with Material UI, Firebase, routing...", "main": "lib/index.js", "module": "es/index.js", diff --git a/packages/rmw-shell/src/containers/Page/FormPage.js b/packages/rmw-shell/src/containers/Page/FormPage.js index 42a5c668..68c8ca6a 100644 --- a/packages/rmw-shell/src/containers/Page/FormPage.js +++ b/packages/rmw-shell/src/containers/Page/FormPage.js @@ -1,78 +1,88 @@ -import Delete from '@mui/icons-material/Delete' -import IconButton from '@mui/material/IconButton' -import Page from 'material-ui-shell/lib/containers/Page' -import React, { useState } from 'react' -import Save from '@mui/icons-material/Save' -import { useNavigate } from 'react-router-dom' -import { usePaths } from '../../providers/Firebase/Paths' -import { useQuestions } from 'material-ui-shell/lib/providers/Dialogs/Question' -import { useAuth } from 'base-shell/lib/providers/Auth' -import FirebaseForm from '../../containers/FirebaseForm' -import { getDatabase, ref, set } from 'firebase/database' +import Delete from "@mui/icons-material/Delete"; +import IconButton from "@mui/material/IconButton"; +import Page from "material-ui-shell/lib/containers/Page"; +import React, { useState } from "react"; +import Save from "@mui/icons-material/Save"; +import { useNavigate } from "react-router-dom"; +import { usePaths } from "../../providers/Firebase/Paths"; +import { useQuestions } from "material-ui-shell/lib/providers/Dialogs/Question"; +import { useAuth } from "base-shell/lib/providers/Auth"; +import FirebaseForm from "../../containers/FirebaseForm"; +import { getDatabase, ref, set } from "firebase/database"; export default function FormPage(props) { const { uid, - path = 'none', + path = "none", getPageProps = () => {}, handleDelete = () => {}, deleteDialogProps = {}, grants = {}, initialValues = {}, - } = props - const navigate = useNavigate() - const { openDialog } = useQuestions() - const { getPath } = usePaths() - const { auth } = useAuth() - const [submit, setSubmit] = useState(false) - const db = getDatabase() - const { isGranted = () => false } = auth || {} + useSave = true, + useDelete = true, + alwaysAllowSave = false, + alwaysAllowDelete = false, + } = props; + const navigate = useNavigate(); + const { openDialog } = useQuestions(); + const { getPath } = usePaths(); + const { auth } = useAuth(); + const [submit, setSubmit] = useState(false); + const db = getDatabase(); + const { isGranted = () => false } = auth || {}; - const databasePath = `${path}/${uid}` - const data = getPath(databasePath, {}) || initialValues + const databasePath = `${path}/${uid}`; + const data = getPath(databasePath, {}) || initialValues; const openDeleteDialog = () => { openDialog({ handleAction: async (handleClose) => { - await set(ref(db, `${path}/${uid}`), null) - handleClose() - handleDelete() + await set(ref(db, `${path}/${uid}`), null); + handleClose(); + handleDelete(); }, ...deleteDialogProps, - }) - } + }); + }; return ( { - navigate(-1) + navigate(-1); }} appBarContent={
- { - submit(e) - }} - > - - + {useSave && ( + { + submit(e); + }} + > + + + )} - { - openDeleteDialog() - }} - > - - + {useDelete && ( + { + openDeleteDialog(); + }} + > + + + )}
} {...getPageProps({ values: data, submit })} >
- ) + ); }