fix: refetch app flows after delete and duplicate
This commit is contained in:
@@ -47,7 +47,7 @@ function AppFlows(props) {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{flows?.map((appFlow) => (
|
{flows?.map((appFlow) => (
|
||||||
<AppFlowRow key={appFlow.id} flow={appFlow} />
|
<AppFlowRow key={appFlow.id} flow={appFlow} appKey={appKey} />
|
||||||
))}
|
))}
|
||||||
|
|
||||||
{pageInfo && pageInfo.totalPages > 1 && (
|
{pageInfo && pageInfo.totalPages > 1 && (
|
||||||
|
@@ -2,6 +2,8 @@ import PropTypes from 'prop-types';
|
|||||||
import { useMutation } from '@apollo/client';
|
import { useMutation } from '@apollo/client';
|
||||||
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 useEnqueueSnackbar from 'hooks/useEnqueueSnackbar';
|
import useEnqueueSnackbar from 'hooks/useEnqueueSnackbar';
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
@@ -13,17 +15,20 @@ import { DUPLICATE_FLOW } from 'graphql/mutations/duplicate-flow';
|
|||||||
import useFormatMessage from 'hooks/useFormatMessage';
|
import useFormatMessage from 'hooks/useFormatMessage';
|
||||||
|
|
||||||
function ContextMenu(props) {
|
function ContextMenu(props) {
|
||||||
const { flowId, onClose, anchorEl, onDuplicateFlow, onDeleteFlow } = props;
|
const { flowId, onClose, anchorEl, onDuplicateFlow, onDeleteFlow, appKey } =
|
||||||
|
props;
|
||||||
const enqueueSnackbar = useEnqueueSnackbar();
|
const enqueueSnackbar = useEnqueueSnackbar();
|
||||||
const [deleteFlow] = useMutation(DELETE_FLOW);
|
|
||||||
const [duplicateFlow] = useMutation(DUPLICATE_FLOW);
|
|
||||||
const formatMessage = useFormatMessage();
|
const formatMessage = useFormatMessage();
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
const [duplicateFlow] = useMutation(DUPLICATE_FLOW);
|
||||||
|
const [deleteFlow] = useMutation(DELETE_FLOW);
|
||||||
|
|
||||||
const onFlowDuplicate = React.useCallback(async () => {
|
const onFlowDuplicate = React.useCallback(async () => {
|
||||||
await duplicateFlow({
|
await duplicateFlow({
|
||||||
variables: { input: { id: flowId } },
|
variables: { input: { id: flowId } },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await queryClient.invalidateQueries({ queryKey: ['appFlows', appKey] });
|
||||||
enqueueSnackbar(formatMessage('flow.successfullyDuplicated'), {
|
enqueueSnackbar(formatMessage('flow.successfullyDuplicated'), {
|
||||||
variant: 'success',
|
variant: 'success',
|
||||||
SnackbarProps: {
|
SnackbarProps: {
|
||||||
@@ -33,7 +38,7 @@ function ContextMenu(props) {
|
|||||||
|
|
||||||
onDuplicateFlow?.();
|
onDuplicateFlow?.();
|
||||||
onClose();
|
onClose();
|
||||||
}, [flowId, onClose, duplicateFlow, onDuplicateFlow]);
|
}, [flowId, onClose, duplicateFlow, queryClient, onDuplicateFlow]);
|
||||||
|
|
||||||
const onFlowDelete = React.useCallback(async () => {
|
const onFlowDelete = React.useCallback(async () => {
|
||||||
await deleteFlow({
|
await deleteFlow({
|
||||||
@@ -49,13 +54,14 @@ function ContextMenu(props) {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await queryClient.invalidateQueries({ queryKey: ['appFlows', appKey] });
|
||||||
enqueueSnackbar(formatMessage('flow.successfullyDeleted'), {
|
enqueueSnackbar(formatMessage('flow.successfullyDeleted'), {
|
||||||
variant: 'success',
|
variant: 'success',
|
||||||
});
|
});
|
||||||
|
|
||||||
onDeleteFlow?.();
|
onDeleteFlow?.();
|
||||||
onClose();
|
onClose();
|
||||||
}, [flowId, onClose, deleteFlow, onDeleteFlow]);
|
}, [flowId, onClose, deleteFlow, queryClient, onDeleteFlow]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Menu
|
<Menu
|
||||||
@@ -100,6 +106,7 @@ ContextMenu.propTypes = {
|
|||||||
]).isRequired,
|
]).isRequired,
|
||||||
onDeleteFlow: PropTypes.func,
|
onDeleteFlow: PropTypes.func,
|
||||||
onDuplicateFlow: PropTypes.func,
|
onDuplicateFlow: PropTypes.func,
|
||||||
|
appKey: PropTypes.string.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default ContextMenu;
|
export default ContextMenu;
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
|
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 IconButton from '@mui/material/IconButton';
|
import IconButton from '@mui/material/IconButton';
|
||||||
@@ -6,7 +7,6 @@ import CardActionArea from '@mui/material/CardActionArea';
|
|||||||
import Chip from '@mui/material/Chip';
|
import Chip from '@mui/material/Chip';
|
||||||
import MoreHorizIcon from '@mui/icons-material/MoreHoriz';
|
import MoreHorizIcon from '@mui/icons-material/MoreHoriz';
|
||||||
import { DateTime } from 'luxon';
|
import { DateTime } from 'luxon';
|
||||||
import PropTypes from 'prop-types';
|
|
||||||
|
|
||||||
import FlowAppIcons from 'components/FlowAppIcons';
|
import FlowAppIcons from 'components/FlowAppIcons';
|
||||||
import FlowContextMenu from 'components/FlowContextMenu';
|
import FlowContextMenu from 'components/FlowContextMenu';
|
||||||
@@ -37,7 +37,7 @@ function FlowRow(props) {
|
|||||||
const formatMessage = useFormatMessage();
|
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 { flow, onDuplicateFlow, onDeleteFlow } = props;
|
const { flow, onDuplicateFlow, onDeleteFlow, appKey } = props;
|
||||||
const handleClose = () => {
|
const handleClose = () => {
|
||||||
setAnchorEl(null);
|
setAnchorEl(null);
|
||||||
};
|
};
|
||||||
@@ -116,6 +116,7 @@ function FlowRow(props) {
|
|||||||
anchorEl={anchorEl}
|
anchorEl={anchorEl}
|
||||||
onDeleteFlow={onDeleteFlow}
|
onDeleteFlow={onDeleteFlow}
|
||||||
onDuplicateFlow={onDuplicateFlow}
|
onDuplicateFlow={onDuplicateFlow}
|
||||||
|
appKey={appKey}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
@@ -126,6 +127,7 @@ FlowRow.propTypes = {
|
|||||||
flow: FlowPropType.isRequired,
|
flow: FlowPropType.isRequired,
|
||||||
onDeleteFlow: PropTypes.func,
|
onDeleteFlow: PropTypes.func,
|
||||||
onDuplicateFlow: PropTypes.func,
|
onDuplicateFlow: PropTypes.func,
|
||||||
|
appKey: PropTypes.string.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default FlowRow;
|
export default FlowRow;
|
||||||
|
Reference in New Issue
Block a user