Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | 1x 1x 1x | import React, { useEffect, useState } from "react"; import { isEmpty } from "lodash"; import { OrganisationForm } from "../components"; import { Grid, Paper } from "@mui/material"; import { connect } from "react-redux"; import { Redirect, useLocation } from "react-router-dom"; import { editOrganisationAction, retrieveOrganisationAction, editOrganisationLoadingSelector, deleteOrganisationAction, deleteOrganisationErrorSelector, editOrganisationErrorSelector } from "../redux"; import { APIOrganisation, EditableOrganisationFields } from "../types"; import { CONTEXT, usePrevious } from "../../../utils"; import { ProgressOverlay, ConfirmationDialog, ToastAlert } from "../../../utils/components"; import Header from "../../../components/Header"; import { MenuButton } from "../components"; import { AppState } from "../../../redux"; interface Props { errors?: {}; editError?: {}; loading: boolean; editedOrganisation?: APIOrganisation; organisation?: APIOrganisation; deleteError?: string; editOrg: (...args: Parameters<typeof editOrganisationAction>) => void; retrieveOrg: (...args: Parameters<typeof retrieveOrganisationAction>) => void; deleteOrg: (...args: Parameters<typeof deleteOrganisationAction>) => void; } const EditOrganisationPage: React.FC<Props> = ({ errors, editError = "", deleteError = "", loading, organisation, editedOrganisation, editOrg, retrieveOrg, deleteOrg }: Props) => { const [openDialog, setOpenDialog] = useState(false); const [openAlert, setOpenAlert] = useState(false); const { pathname } = useLocation(); const orgUrl = pathname.replace("/user", "").replace("edit/", ""); const previouslyLoading = usePrevious(loading); useEffect(() => { retrieveOrg(orgUrl); }, [orgUrl, retrieveOrg]); if (!loading && previouslyLoading && editedOrganisation) { return <Redirect to={orgUrl} />; } const { name = "" } = organisation || {}; const confirmationMsg = () => { return ( <div> <h5 id="modal-title"> Delete: <b>{name}</b> </h5> <p id="delete-modal-description"> Are you sure you want to Delete? This could mean that you loose all the data within this organisation. </p> </div> ); }; return ( <Header title="Edit Organisation" backUrl={orgUrl} backText="Back to organisation" > <ToastAlert open={openAlert} setOpen={() => setOpenAlert(!openAlert)} message={deleteError} type="error" /> {editError ? ( <ToastAlert open={openAlert} setOpen={() => setOpenAlert(!openAlert)} message="An error occured" type="error" /> ) : null} <ProgressOverlay loading={loading}> <Grid id="edit-organisation-page" item xs={6} component="div"> <Paper> <OrganisationForm context={CONTEXT.edit} errors={errors} loading={loading} savedValues={!isEmpty(organisation) ? organisation : organisation} onSubmit={(values: EditableOrganisationFields) => { editOrg(orgUrl, values); setOpenAlert(true); }} /> </Paper> </Grid> <MenuButton backUrl={orgUrl} confirmDelete={() => setOpenDialog(true)} /> <ConfirmationDialog open={openDialog} setOpen={() => setOpenDialog(!openDialog)} onConfirm={() => { deleteOrg(orgUrl); setOpenDialog(!openDialog); setOpenAlert(true); }} message={confirmationMsg()} cancelButtonText={"No"} confirmButtonText={"Yes"} /> </ProgressOverlay> </Header> ); }; const mapStateToProps = (state: AppState) => ({ editedOrganisation: state.organisations.editedOrganisation, organisation: state.organisations.organisation, loading: editOrganisationLoadingSelector(state), deleteError: deleteOrganisationErrorSelector(state), editError: editOrganisationErrorSelector(state) }); const mapActionsToProps = { editOrg: editOrganisationAction, retrieveOrg: retrieveOrganisationAction, deleteOrg: deleteOrganisationAction }; export default connect( mapStateToProps, mapActionsToProps )(EditOrganisationPage); |