feat: handle 404 template error
This commit is contained in:
@@ -1,44 +1,37 @@
|
|||||||
import Menu from '@mui/material/Menu';
|
import Menu from '@mui/material/Menu';
|
||||||
import MenuItem from '@mui/material/MenuItem';
|
import MenuItem from '@mui/material/MenuItem';
|
||||||
import { useQueryClient } from '@tanstack/react-query';
|
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { Link, useNavigate } from 'react-router-dom';
|
|
||||||
|
|
||||||
import Can from 'components/Can';
|
import Can from 'components/Can';
|
||||||
import FlowFolderChangeDialog from 'components/FlowFolderChangeDialog';
|
|
||||||
import * as URLS from 'config/urls';
|
|
||||||
import useAdminDeleteTemplate from 'hooks/useAdminDeleteTemplate.ee';
|
import useAdminDeleteTemplate from 'hooks/useAdminDeleteTemplate.ee';
|
||||||
import useDownloadJsonAsFile from 'hooks/useDownloadJsonAsFile';
|
|
||||||
import useDuplicateFlow from 'hooks/useDuplicateFlow';
|
|
||||||
import useEnqueueSnackbar from 'hooks/useEnqueueSnackbar';
|
import useEnqueueSnackbar from 'hooks/useEnqueueSnackbar';
|
||||||
import useExportFlow from 'hooks/useExportFlow';
|
|
||||||
import useFormatMessage from 'hooks/useFormatMessage';
|
import useFormatMessage from 'hooks/useFormatMessage';
|
||||||
import useIsCurrentUserAdmin from 'hooks/useIsCurrentUserAdmin';
|
|
||||||
|
|
||||||
function AdminTemplateContextMenu(props) {
|
function AdminTemplateContextMenu(props) {
|
||||||
const { templateId, onClose, anchorEl } = props;
|
const { templateId, onClose, anchorEl } = props;
|
||||||
|
|
||||||
const [showFlowFolderChangeDialog, setShowFlowFolderChangeDialog] =
|
|
||||||
React.useState(false);
|
|
||||||
|
|
||||||
const navigate = useNavigate();
|
|
||||||
const enqueueSnackbar = useEnqueueSnackbar();
|
const enqueueSnackbar = useEnqueueSnackbar();
|
||||||
const formatMessage = useFormatMessage();
|
const formatMessage = useFormatMessage();
|
||||||
const isCurrentUserAdmin = useIsCurrentUserAdmin();
|
|
||||||
const { mutateAsync: deleteTemplate } = useAdminDeleteTemplate(templateId);
|
const { mutateAsync: deleteTemplate } = useAdminDeleteTemplate(templateId);
|
||||||
|
|
||||||
const onTemplateDelete = React.useCallback(async () => {
|
const onTemplateDelete = React.useCallback(async () => {
|
||||||
await deleteTemplate();
|
try {
|
||||||
|
await deleteTemplate();
|
||||||
|
|
||||||
enqueueSnackbar(
|
enqueueSnackbar(
|
||||||
formatMessage('adminTemplateContextMenu.successfullyDeleted'),
|
formatMessage('adminTemplateContextMenu.successfullyDeleted'),
|
||||||
{
|
{
|
||||||
variant: 'success',
|
variant: 'success',
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
onClose();
|
onClose();
|
||||||
|
} catch (error) {
|
||||||
|
enqueueSnackbar(error?.message || formatMessage('genericError'), {
|
||||||
|
variant: 'error',
|
||||||
|
});
|
||||||
|
}
|
||||||
}, [deleteTemplate, enqueueSnackbar, formatMessage, onClose]);
|
}, [deleteTemplate, enqueueSnackbar, formatMessage, onClose]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,43 +1,20 @@
|
|||||||
import AddIcon from '@mui/icons-material/Add';
|
import AddIcon from '@mui/icons-material/Add';
|
||||||
import UploadIcon from '@mui/icons-material/Upload';
|
import UploadIcon from '@mui/icons-material/Upload';
|
||||||
import Box from '@mui/material/Box';
|
|
||||||
import CircularProgress from '@mui/material/CircularProgress';
|
|
||||||
import Divider from '@mui/material/Divider';
|
|
||||||
import Grid from '@mui/material/Grid';
|
|
||||||
import Button from '@mui/material/Button';
|
import Button from '@mui/material/Button';
|
||||||
import Pagination from '@mui/material/Pagination';
|
|
||||||
import { useTheme } from '@mui/material/styles';
|
import { useTheme } from '@mui/material/styles';
|
||||||
import useMediaQuery from '@mui/material/useMediaQuery';
|
import useMediaQuery from '@mui/material/useMediaQuery';
|
||||||
import PaginationItem from '@mui/material/PaginationItem';
|
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import {
|
import { Link } from 'react-router-dom';
|
||||||
Link,
|
|
||||||
Route,
|
|
||||||
Routes,
|
|
||||||
useNavigate,
|
|
||||||
useSearchParams,
|
|
||||||
} from 'react-router-dom';
|
|
||||||
|
|
||||||
import Can from 'components/Can';
|
|
||||||
import ConditionalIconButton from 'components/ConditionalIconButton';
|
|
||||||
import Container from 'components/Container';
|
|
||||||
import FlowRow from 'components/FlowRow';
|
|
||||||
import Folders from 'components/Folders';
|
|
||||||
import ImportFlowDialog from 'components/ImportFlowDialog';
|
|
||||||
import SplitButton from 'components/SplitButton';
|
import SplitButton from 'components/SplitButton';
|
||||||
import NoResultFound from 'components/NoResultFound';
|
|
||||||
import PageTitle from 'components/PageTitle';
|
|
||||||
import SearchInput from 'components/SearchInput';
|
|
||||||
import TemplatesDialog from 'components/TemplatesDialog/index.ee';
|
|
||||||
import * as URLS from 'config/urls';
|
import * as URLS from 'config/urls';
|
||||||
import useCurrentUserAbility from 'hooks/useCurrentUserAbility';
|
import useCurrentUserAbility from 'hooks/useCurrentUserAbility';
|
||||||
import useFlows from 'hooks/useFlows';
|
|
||||||
import useFormatMessage from 'hooks/useFormatMessage';
|
import useFormatMessage from 'hooks/useFormatMessage';
|
||||||
import useAutomatischConfig from 'hooks/useAutomatischConfig';
|
import useAutomatischConfig from 'hooks/useAutomatischConfig';
|
||||||
|
|
||||||
export default function FlowsButtons() {
|
export default function FlowsButtons() {
|
||||||
const formatMessage = useFormatMessage();
|
const formatMessage = useFormatMessage();
|
||||||
const navigate = useNavigate();
|
|
||||||
const currentUserAbility = useCurrentUserAbility();
|
const currentUserAbility = useCurrentUserAbility();
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const { data: config } = useAutomatischConfig();
|
const { data: config } = useAutomatischConfig();
|
||||||
|
|||||||
@@ -3,20 +3,16 @@ import PropTypes from 'prop-types';
|
|||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
import Card from '@mui/material/Card';
|
import Card from '@mui/material/Card';
|
||||||
import CardActionArea from '@mui/material/CardActionArea';
|
import CardActionArea from '@mui/material/CardActionArea';
|
||||||
import { DateTime } from 'luxon';
|
|
||||||
import IconButton from '@mui/material/IconButton';
|
import IconButton from '@mui/material/IconButton';
|
||||||
import MoreHorizIcon from '@mui/icons-material/MoreHoriz';
|
import MoreHorizIcon from '@mui/icons-material/MoreHoriz';
|
||||||
|
|
||||||
import FlowAppIcons from 'components/FlowAppIcons';
|
import FlowAppIcons from 'components/FlowAppIcons';
|
||||||
import AdminTemplateContextMenu from 'components/AdminTemplateContextMenu';
|
import AdminTemplateContextMenu from 'components/AdminTemplateContextMenu';
|
||||||
import useFormatMessage from 'hooks/useFormatMessage';
|
|
||||||
import * as URLS from 'config/urls';
|
|
||||||
import { Apps, CardContent, ContextMenu, Title, Typography } from './style';
|
import { Apps, CardContent, ContextMenu, Title, Typography } from './style';
|
||||||
import { FlowPropType } from 'propTypes/propTypes';
|
import { FlowPropType } from 'propTypes/propTypes';
|
||||||
import useIsCurrentUserAdmin from 'hooks/useIsCurrentUserAdmin';
|
import useIsCurrentUserAdmin from 'hooks/useIsCurrentUserAdmin';
|
||||||
|
|
||||||
function TemplateItem(props) {
|
function TemplateItem(props) {
|
||||||
const formatMessage = useFormatMessage();
|
|
||||||
const contextButtonRef = React.useRef(null);
|
const contextButtonRef = React.useRef(null);
|
||||||
const [anchorEl, setAnchorEl] = React.useState(null);
|
const [anchorEl, setAnchorEl] = React.useState(null);
|
||||||
const isCurrentUserAdmin = useIsCurrentUserAdmin();
|
const isCurrentUserAdmin = useIsCurrentUserAdmin();
|
||||||
|
|||||||
@@ -1,23 +1,16 @@
|
|||||||
import AddIcon from '@mui/icons-material/Add';
|
|
||||||
import CloseIcon from '@mui/icons-material/Close';
|
import CloseIcon from '@mui/icons-material/Close';
|
||||||
import Alert from '@mui/material/Alert';
|
|
||||||
import Button from '@mui/material/Button';
|
|
||||||
import Dialog from '@mui/material/Dialog';
|
import Dialog from '@mui/material/Dialog';
|
||||||
import DialogActions from '@mui/material/DialogActions';
|
|
||||||
import DialogContent from '@mui/material/DialogContent';
|
import DialogContent from '@mui/material/DialogContent';
|
||||||
import DialogContentText from '@mui/material/DialogContentText';
|
import DialogContentText from '@mui/material/DialogContentText';
|
||||||
import DialogTitle from '@mui/material/DialogTitle';
|
import DialogTitle from '@mui/material/DialogTitle';
|
||||||
import IconButton from '@mui/material/IconButton';
|
import IconButton from '@mui/material/IconButton';
|
||||||
import TextField from '@mui/material/TextField';
|
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
|
||||||
import * as URLS from 'config/urls';
|
import * as URLS from 'config/urls';
|
||||||
import { getUnifiedErrorMessage } from 'helpers/errors';
|
|
||||||
import useTemplates from 'hooks/useTemplates.ee';
|
import useTemplates from 'hooks/useTemplates.ee';
|
||||||
import useFormatMessage from 'hooks/useFormatMessage';
|
import useFormatMessage from 'hooks/useFormatMessage';
|
||||||
import TemplateItem from './TemplateItem/TemplateItem.ee';
|
import TemplateItem from './TemplateItem/TemplateItem.ee';
|
||||||
import NoResultFound from 'components/NoResultFound';
|
|
||||||
|
|
||||||
export default function TemplatesDialog(props) {
|
export default function TemplatesDialog(props) {
|
||||||
const { open = true } = props;
|
const { open = true } = props;
|
||||||
|
|||||||
@@ -16,6 +16,9 @@ export default function useAdminDeleteTemplate(templateId) {
|
|||||||
await queryClient.invalidateQueries({
|
await queryClient.invalidateQueries({
|
||||||
queryKey: ['admin', 'templates'],
|
queryKey: ['admin', 'templates'],
|
||||||
});
|
});
|
||||||
|
await queryClient.invalidateQueries({
|
||||||
|
queryKey: ['templates'],
|
||||||
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import LoadingButton from '@mui/lab/LoadingButton';
|
import LoadingButton from '@mui/lab/LoadingButton';
|
||||||
import Grid from '@mui/material/Grid';
|
import Grid from '@mui/material/Grid';
|
||||||
import Skeleton from '@mui/material/Skeleton';
|
|
||||||
import Stack from '@mui/material/Stack';
|
import Stack from '@mui/material/Stack';
|
||||||
import { useNavigate, useParams } from 'react-router-dom';
|
import { useNavigate, useParams } from 'react-router-dom';
|
||||||
|
|
||||||
@@ -10,8 +9,6 @@ import Form from 'components/Form';
|
|||||||
import PageTitle from 'components/PageTitle';
|
import PageTitle from 'components/PageTitle';
|
||||||
import TextField from 'components/TextField';
|
import TextField from 'components/TextField';
|
||||||
import useFlow from 'hooks/useFlow';
|
import useFlow from 'hooks/useFlow';
|
||||||
import useAutomatischConfig from 'hooks/useAutomatischConfig';
|
|
||||||
import useEnqueueSnackbar from 'hooks/useEnqueueSnackbar';
|
|
||||||
import useFormatMessage from 'hooks/useFormatMessage';
|
import useFormatMessage from 'hooks/useFormatMessage';
|
||||||
import useAdminCreateTemplate from 'hooks/useAdminCreateTemplate.ee';
|
import useAdminCreateTemplate from 'hooks/useAdminCreateTemplate.ee';
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import LoadingButton from '@mui/lab/LoadingButton';
|
import LoadingButton from '@mui/lab/LoadingButton';
|
||||||
import Grid from '@mui/material/Grid';
|
import Grid from '@mui/material/Grid';
|
||||||
import Skeleton from '@mui/material/Skeleton';
|
|
||||||
import Stack from '@mui/material/Stack';
|
import Stack from '@mui/material/Stack';
|
||||||
|
import Alert from '@mui/material/Alert';
|
||||||
import { useParams } from 'react-router-dom';
|
import { useParams } from 'react-router-dom';
|
||||||
|
|
||||||
import Container from 'components/Container';
|
import Container from 'components/Container';
|
||||||
@@ -9,8 +9,6 @@ import Form from 'components/Form';
|
|||||||
import PageTitle from 'components/PageTitle';
|
import PageTitle from 'components/PageTitle';
|
||||||
import TextField from 'components/TextField';
|
import TextField from 'components/TextField';
|
||||||
import useAdminTemplate from 'hooks/useAdminTemplate.ee';
|
import useAdminTemplate from 'hooks/useAdminTemplate.ee';
|
||||||
import useAutomatischConfig from 'hooks/useAutomatischConfig';
|
|
||||||
import useEnqueueSnackbar from 'hooks/useEnqueueSnackbar';
|
|
||||||
import useFormatMessage from 'hooks/useFormatMessage';
|
import useFormatMessage from 'hooks/useFormatMessage';
|
||||||
import useAdminUpdateTemplate from 'hooks/useAdminUpdateTemplate.ee';
|
import useAdminUpdateTemplate from 'hooks/useAdminUpdateTemplate.ee';
|
||||||
|
|
||||||
@@ -18,8 +16,12 @@ function AdminUpdateTemplatePage() {
|
|||||||
const formatMessage = useFormatMessage();
|
const formatMessage = useFormatMessage();
|
||||||
const { templateId } = useParams();
|
const { templateId } = useParams();
|
||||||
|
|
||||||
const { data: template, isLoading: isTemplateLoading } =
|
const {
|
||||||
useAdminTemplate(templateId);
|
data: template,
|
||||||
|
isLoading: isTemplateLoading,
|
||||||
|
isError: isTemplateError,
|
||||||
|
error: templateError,
|
||||||
|
} = useAdminTemplate(templateId);
|
||||||
|
|
||||||
const { mutateAsync: updateTemplate, isPending } =
|
const { mutateAsync: updateTemplate, isPending } =
|
||||||
useAdminUpdateTemplate(templateId);
|
useAdminUpdateTemplate(templateId);
|
||||||
@@ -38,12 +40,13 @@ function AdminUpdateTemplatePage() {
|
|||||||
<Grid item xs={12} sx={{ pt: 5, pb: 5 }}>
|
<Grid item xs={12} sx={{ pt: 5, pb: 5 }}>
|
||||||
<Stack spacing={5}></Stack>
|
<Stack spacing={5}></Stack>
|
||||||
{!isTemplateLoading && (
|
{!isTemplateLoading && (
|
||||||
<Form onSubmit={handleFormSubmit} defaultValues={template.data}>
|
<Form onSubmit={handleFormSubmit} defaultValues={template?.data}>
|
||||||
<Stack direction="column" gap={2}>
|
<Stack direction="column" gap={2}>
|
||||||
<TextField
|
<TextField
|
||||||
name="name"
|
name="name"
|
||||||
label={formatMessage('adminUpdateTemplate.titleFieldLabel')}
|
label={formatMessage('adminUpdateTemplate.titleFieldLabel')}
|
||||||
fullWidth
|
fullWidth
|
||||||
|
disabled={!template}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<LoadingButton
|
<LoadingButton
|
||||||
@@ -53,12 +56,18 @@ function AdminUpdateTemplatePage() {
|
|||||||
sx={{ boxShadow: 2 }}
|
sx={{ boxShadow: 2 }}
|
||||||
loading={isPending}
|
loading={isPending}
|
||||||
data-test="update-button"
|
data-test="update-button"
|
||||||
|
disabled={!template}
|
||||||
>
|
>
|
||||||
{formatMessage('adminUpdateTemplate.submit')}
|
{formatMessage('adminUpdateTemplate.submit')}
|
||||||
</LoadingButton>
|
</LoadingButton>
|
||||||
</Stack>
|
</Stack>
|
||||||
</Form>
|
</Form>
|
||||||
)}
|
)}
|
||||||
|
{isTemplateError && (
|
||||||
|
<Alert severity="error" sx={{ mt: 3 }}>
|
||||||
|
{templateError?.message || formatMessage('genericError')}
|
||||||
|
</Alert>
|
||||||
|
)}
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Container>
|
</Container>
|
||||||
|
|||||||
@@ -11,19 +11,27 @@ export default function CreateFlow() {
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const formatMessage = useFormatMessage();
|
const formatMessage = useFormatMessage();
|
||||||
const [searchParams] = useSearchParams();
|
const [searchParams] = useSearchParams();
|
||||||
const { mutateAsync: createFlow, isCreateFlowError } = useCreateFlow();
|
const {
|
||||||
|
mutateAsync: createFlow,
|
||||||
|
isCreateFlowError,
|
||||||
|
isError,
|
||||||
|
isPending,
|
||||||
|
error,
|
||||||
|
} = useCreateFlow();
|
||||||
|
|
||||||
const navigateToEditor = (flowId) =>
|
const navigateToEditor = (flowId) =>
|
||||||
navigate(URLS.FLOW_EDITOR(flowId), { replace: true });
|
navigate(URLS.FLOW_EDITOR(flowId), { replace: true });
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
async function initiate() {
|
async function initiate() {
|
||||||
const templateId = searchParams.get('templateId');
|
try {
|
||||||
const response = await createFlow({ templateId });
|
const templateId = searchParams.get('templateId');
|
||||||
|
const response = await createFlow({ templateId });
|
||||||
|
|
||||||
const flowId = response.data?.id;
|
const flowId = response.data?.id;
|
||||||
|
|
||||||
navigateToEditor(flowId);
|
navigateToEditor(flowId);
|
||||||
|
} catch {}
|
||||||
}
|
}
|
||||||
|
|
||||||
initiate();
|
initiate();
|
||||||
@@ -44,11 +52,19 @@ export default function CreateFlow() {
|
|||||||
gap: 2,
|
gap: 2,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<CircularProgress size={16} thickness={7.5} />
|
{isPending && (
|
||||||
|
<>
|
||||||
<Typography variant="body2">
|
<CircularProgress size={16} thickness={7.5} />
|
||||||
{formatMessage('createFlow.creating')}
|
<Typography variant="body2">
|
||||||
</Typography>
|
{formatMessage('createFlow.creating')}
|
||||||
|
</Typography>{' '}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
{isError && (
|
||||||
|
<Typography variant="body2">
|
||||||
|
{error?.message || formatMessage('genericError')}
|
||||||
|
</Typography>
|
||||||
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
import AddIcon from '@mui/icons-material/Add';
|
|
||||||
import UploadIcon from '@mui/icons-material/Upload';
|
|
||||||
import Box from '@mui/material/Box';
|
import Box from '@mui/material/Box';
|
||||||
import CircularProgress from '@mui/material/CircularProgress';
|
import CircularProgress from '@mui/material/CircularProgress';
|
||||||
import Divider from '@mui/material/Divider';
|
import Divider from '@mui/material/Divider';
|
||||||
@@ -15,10 +13,8 @@ import {
|
|||||||
useSearchParams,
|
useSearchParams,
|
||||||
} from 'react-router-dom';
|
} from 'react-router-dom';
|
||||||
|
|
||||||
import Can from 'components/Can';
|
|
||||||
import FlowFilters from 'components/FlowFilters';
|
import FlowFilters from 'components/FlowFilters';
|
||||||
import FlowsButtons from 'components/FlowsButtons';
|
import FlowsButtons from 'components/FlowsButtons';
|
||||||
import ConditionalIconButton from 'components/ConditionalIconButton';
|
|
||||||
import Container from 'components/Container';
|
import Container from 'components/Container';
|
||||||
import FlowRow from 'components/FlowRow';
|
import FlowRow from 'components/FlowRow';
|
||||||
import Folders from 'components/Folders';
|
import Folders from 'components/Folders';
|
||||||
|
|||||||
Reference in New Issue
Block a user