Skip to content

Commit

Permalink
Updated FirebaseForm Page
Browse files Browse the repository at this point in the history
  • Loading branch information
Tarik Huber authored and Tarik Huber committed Jul 25, 2023
1 parent 0c03e2e commit 503a76e
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 50 deletions.
4 changes: 2 additions & 2 deletions packages/rmw-shell/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/rmw-shell/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
104 changes: 57 additions & 47 deletions packages/rmw-shell/src/containers/Page/FormPage.js
Original file line number Diff line number Diff line change
@@ -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 (
<Page
onBackClick={() => {
navigate(-1)
navigate(-1);
}}
appBarContent={
<div>
<IconButton
disabled={!isGranted(auth, grants.create)}
color="inherit"
onClick={(e) => {
submit(e)
}}
>
<Save />
</IconButton>
{useSave && (
<IconButton
disabled={!isGranted(auth, grants.create) && !alwaysAllowSave}
color="inherit"
onClick={(e) => {
submit(e);
}}
>
<Save />
</IconButton>
)}

<IconButton
disabled={!uid || !isGranted(auth, grants.delete)}
color="inherit"
onClick={() => {
openDeleteDialog()
}}
>
<Delete />
</IconButton>
{useDelete && (
<IconButton
disabled={
!uid || (!isGranted(auth, grants.delete) && !alwaysAllowDelete)
}
color="inherit"
onClick={() => {
openDeleteDialog();
}}
>
<Delete />
</IconButton>
)}
</div>
}
{...getPageProps({ values: data, submit })}
>
<FirebaseForm setSubmit={setSubmit} submit={submit} {...props} />
</Page>
)
);
}

0 comments on commit 503a76e

Please sign in to comment.