feat(FlowFolderChangeDialog): allow action only for flow owners
This commit is contained in:
@@ -14,7 +14,6 @@ import CloseIcon from '@mui/icons-material/Close';
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
|
|
||||||
import useFlow from 'hooks/useFlow';
|
import useFlow from 'hooks/useFlow';
|
||||||
import useCurrentUser from 'hooks/useCurrentUser';
|
|
||||||
import useFolders from 'hooks/useFolders';
|
import useFolders from 'hooks/useFolders';
|
||||||
import useFormatMessage from 'hooks/useFormatMessage';
|
import useFormatMessage from 'hooks/useFormatMessage';
|
||||||
import useFlowFolder from 'hooks/useFlowFolder';
|
import useFlowFolder from 'hooks/useFlowFolder';
|
||||||
@@ -29,11 +28,8 @@ function FlowFolderChangeDialog(props) {
|
|||||||
useFlowFolder(flowId);
|
useFlowFolder(flowId);
|
||||||
const { data: flowData, isPending: isFlowPending } = useFlow(flowId);
|
const { data: flowData, isPending: isFlowPending } = useFlow(flowId);
|
||||||
const flow = flowData?.data;
|
const flow = flowData?.data;
|
||||||
const { data: userData, isPending: isCurrentUserPending } = useCurrentUser();
|
|
||||||
const currentUser = userData?.data;
|
|
||||||
|
|
||||||
const [selectedFolder, setSelectedFolder] = React.useState(null);
|
const [selectedFolder, setSelectedFolder] = React.useState(null);
|
||||||
const [canMoveFlow, setCanMoveFlow] = React.useState(false);
|
|
||||||
|
|
||||||
const uncategorizedFolder = { id: null, name: 'Uncategorized' };
|
const uncategorizedFolder = { id: null, name: 'Uncategorized' };
|
||||||
|
|
||||||
@@ -61,16 +57,6 @@ function FlowFolderChangeDialog(props) {
|
|||||||
[flowFolder],
|
[flowFolder],
|
||||||
);
|
);
|
||||||
|
|
||||||
React.useEffect(
|
|
||||||
function updateCanMoveFlow() {
|
|
||||||
if (flow?.user_id && currentUser?.id) {
|
|
||||||
// TODO: flow.user_id is currently unavailable, preventing this from running. Remove this comment once it becomes available.
|
|
||||||
setCanMoveFlow(flow.user_id === currentUser.id);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[currentUser?.id, flow?.user_id],
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={open} onClose={onClose}>
|
<Dialog open={open} onClose={onClose}>
|
||||||
<DialogTitle>{formatMessage('flowFolderChangeDialog.title')}</DialogTitle>
|
<DialogTitle>{formatMessage('flowFolderChangeDialog.title')}</DialogTitle>
|
||||||
@@ -105,13 +91,8 @@ function FlowFolderChangeDialog(props) {
|
|||||||
isOptionEqualToValue={(option, value) => option.id === value.id}
|
isOptionEqualToValue={(option, value) => option.id === value.id}
|
||||||
getOptionLabel={(option) => option.name}
|
getOptionLabel={(option) => option.name}
|
||||||
loading={isFoldersLoading || isFlowFolderLoading}
|
loading={isFoldersLoading || isFlowFolderLoading}
|
||||||
disabled={
|
disabled={isFoldersLoading || isFlowFolderLoading || isFlowPending}
|
||||||
isFoldersLoading ||
|
readOnly={!flow?.isOwner}
|
||||||
isFlowFolderLoading ||
|
|
||||||
isCurrentUserPending ||
|
|
||||||
isFlowPending
|
|
||||||
}
|
|
||||||
readOnly={!canMoveFlow}
|
|
||||||
renderInput={(params) => (
|
renderInput={(params) => (
|
||||||
<TextField
|
<TextField
|
||||||
{...params}
|
{...params}
|
||||||
@@ -139,13 +120,13 @@ function FlowFolderChangeDialog(props) {
|
|||||||
onClick={handleConfirm}
|
onClick={handleConfirm}
|
||||||
data-test="flow-folder-change-dialog-confirm-button"
|
data-test="flow-folder-change-dialog-confirm-button"
|
||||||
loading={isUpdateFlowFolderPending}
|
loading={isUpdateFlowFolderPending}
|
||||||
disabled={!canMoveFlow}
|
disabled={!flow?.isOwner}
|
||||||
>
|
>
|
||||||
{formatMessage('flowFolderChangeDialog.confirm')}
|
{formatMessage('flowFolderChangeDialog.confirm')}
|
||||||
</LoadingButton>
|
</LoadingButton>
|
||||||
</DialogActions>
|
</DialogActions>
|
||||||
|
|
||||||
{!canMoveFlow && (
|
{!flow?.isOwner && (
|
||||||
<Alert severity="info">
|
<Alert severity="info">
|
||||||
{formatMessage('flowFolder.cannotMoveFlow')}
|
{formatMessage('flowFolder.cannotMoveFlow')}
|
||||||
</Alert>
|
</Alert>
|
||||||
|
|||||||
Reference in New Issue
Block a user