feat: disable submitting when submitting is in progress
This commit is contained in:
@@ -51,26 +51,29 @@ function ChooseConnectionSubstep(props) {
|
|||||||
} = props;
|
} = props;
|
||||||
const { appKey } = step;
|
const { appKey } = step;
|
||||||
const formatMessage = useFormatMessage();
|
const formatMessage = useFormatMessage();
|
||||||
|
const enqueueSnackbar = useEnqueueSnackbar();
|
||||||
|
|
||||||
const editorContext = React.useContext(EditorContext);
|
const editorContext = React.useContext(EditorContext);
|
||||||
const [showAddConnectionDialog, setShowAddConnectionDialog] =
|
const [showAddConnectionDialog, setShowAddConnectionDialog] =
|
||||||
React.useState(false);
|
React.useState(false);
|
||||||
const [showAddSharedConnectionDialog, setShowAddSharedConnectionDialog] =
|
const [showAddSharedConnectionDialog, setShowAddSharedConnectionDialog] =
|
||||||
React.useState(false);
|
React.useState(false);
|
||||||
|
const [submitting, setSubmitting] = React.useState(false);
|
||||||
|
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const { data: appOAuthClients } = useOAuthClients(application.key);
|
|
||||||
const enqueueSnackbar = useEnqueueSnackbar();
|
|
||||||
|
|
||||||
const { authenticate } = useAuthenticateApp({
|
const { authenticate } = useAuthenticateApp({
|
||||||
appKey: application.key,
|
appKey: application.key,
|
||||||
useShared: true,
|
useShared: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
const {
|
const { data: appOAuthClients } = useOAuthClients(application.key);
|
||||||
data,
|
|
||||||
isLoading: isAppConnectionsLoading,
|
|
||||||
refetch,
|
|
||||||
} = useAppConnections(appKey);
|
|
||||||
|
|
||||||
|
const {
|
||||||
|
data: appConnectionsData,
|
||||||
|
isLoading: isAppConnectionsLoading,
|
||||||
|
refetch: refetchAppConnections,
|
||||||
|
} = useAppConnections(appKey);
|
||||||
const { data: appConfig } = useAppConfig(application.key);
|
const { data: appConfig } = useAppConfig(application.key);
|
||||||
|
|
||||||
const { data: stepConnectionData } = useStepConnection(step.id);
|
const { data: stepConnectionData } = useStepConnection(step.id);
|
||||||
@@ -94,7 +97,7 @@ function ChooseConnectionSubstep(props) {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const connectionOptions = React.useMemo(() => {
|
const connectionOptions = React.useMemo(() => {
|
||||||
const appWithConnections = data?.data;
|
const appWithConnections = appConnectionsData?.data;
|
||||||
const options =
|
const options =
|
||||||
appWithConnections?.map((connection) => optionGenerator(connection)) ||
|
appWithConnections?.map((connection) => optionGenerator(connection)) ||
|
||||||
[];
|
[];
|
||||||
@@ -140,7 +143,7 @@ function ChooseConnectionSubstep(props) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return options.concat([addCustomConnection, addConnectionWithOAuthClient]);
|
return options.concat([addCustomConnection, addConnectionWithOAuthClient]);
|
||||||
}, [data, formatMessage, appConfig, appOAuthClients]);
|
}, [appConnectionsData, formatMessage, appConfig, appOAuthClients]);
|
||||||
|
|
||||||
const handleClientClick = async (oauthClientId) => {
|
const handleClientClick = async (oauthClientId) => {
|
||||||
try {
|
try {
|
||||||
@@ -150,7 +153,7 @@ function ChooseConnectionSubstep(props) {
|
|||||||
const connectionId = response?.createConnection.id;
|
const connectionId = response?.createConnection.id;
|
||||||
|
|
||||||
if (connectionId) {
|
if (connectionId) {
|
||||||
await refetch();
|
await refetchAppConnections();
|
||||||
onChange({
|
onChange({
|
||||||
step: {
|
step: {
|
||||||
...step,
|
...step,
|
||||||
@@ -173,11 +176,12 @@ function ChooseConnectionSubstep(props) {
|
|||||||
|
|
||||||
const handleAddConnectionClose = React.useCallback(
|
const handleAddConnectionClose = React.useCallback(
|
||||||
async (response) => {
|
async (response) => {
|
||||||
|
setSubmitting(true);
|
||||||
setShowAddConnectionDialog(false);
|
setShowAddConnectionDialog(false);
|
||||||
const connectionId = response?.createConnection?.id;
|
const connectionId = response?.createConnection?.id;
|
||||||
if (connectionId) {
|
if (connectionId) {
|
||||||
await refetch();
|
await refetchAppConnections();
|
||||||
onChange({
|
await onChange({
|
||||||
step: {
|
step: {
|
||||||
...step,
|
...step,
|
||||||
connection: {
|
connection: {
|
||||||
@@ -186,27 +190,23 @@ function ChooseConnectionSubstep(props) {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
setSubmitting(false);
|
||||||
},
|
},
|
||||||
[onChange, refetch, step],
|
[onChange, refetchAppConnections, step],
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleChange = React.useCallback(
|
const handleChange = React.useCallback(
|
||||||
async (event, selectedOption) => {
|
async (event, selectedOption) => {
|
||||||
if (typeof selectedOption === 'object') {
|
if (typeof selectedOption === 'object') {
|
||||||
|
setSubmitting(true);
|
||||||
const connectionId = selectedOption?.value;
|
const connectionId = selectedOption?.value;
|
||||||
|
|
||||||
if (connectionId === ADD_CONNECTION_VALUE) {
|
if (connectionId === ADD_CONNECTION_VALUE) {
|
||||||
setShowAddConnectionDialog(true);
|
setShowAddConnectionDialog(true);
|
||||||
return;
|
} else if (connectionId === ADD_SHARED_CONNECTION_VALUE) {
|
||||||
}
|
|
||||||
|
|
||||||
if (connectionId === ADD_SHARED_CONNECTION_VALUE) {
|
|
||||||
setShowAddSharedConnectionDialog(true);
|
setShowAddSharedConnectionDialog(true);
|
||||||
return;
|
} else if (connectionId !== stepConnection?.id) {
|
||||||
}
|
await onChange({
|
||||||
|
|
||||||
if (connectionId !== stepConnection?.id) {
|
|
||||||
onChange({
|
|
||||||
step: {
|
step: {
|
||||||
...step,
|
...step,
|
||||||
connection: {
|
connection: {
|
||||||
@@ -219,6 +219,7 @@ function ChooseConnectionSubstep(props) {
|
|||||||
queryKey: ['steps', step.id, 'connection'],
|
queryKey: ['steps', step.id, 'connection'],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
setSubmitting(false);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[stepConnection?.id, onChange, step, queryClient],
|
[stepConnection?.id, onChange, step, queryClient],
|
||||||
@@ -259,7 +260,9 @@ function ChooseConnectionSubstep(props) {
|
|||||||
fullWidth
|
fullWidth
|
||||||
disablePortal
|
disablePortal
|
||||||
disableClearable
|
disableClearable
|
||||||
disabled={editorContext.readOnly}
|
disabled={
|
||||||
|
editorContext.readOnly || isTestConnectionPending || submitting
|
||||||
|
}
|
||||||
options={connectionOptions}
|
options={connectionOptions}
|
||||||
renderInput={(params) => (
|
renderInput={(params) => (
|
||||||
<TextField
|
<TextField
|
||||||
@@ -283,6 +286,7 @@ function ChooseConnectionSubstep(props) {
|
|||||||
onClick={onSubmit}
|
onClick={onSubmit}
|
||||||
sx={{ mt: 2 }}
|
sx={{ mt: 2 }}
|
||||||
disabled={
|
disabled={
|
||||||
|
submitting ||
|
||||||
isTestConnectionPending ||
|
isTestConnectionPending ||
|
||||||
!stepConnection?.verified ||
|
!stepConnection?.verified ||
|
||||||
editorContext.readOnly
|
editorContext.readOnly
|
||||||
|
|||||||
@@ -176,9 +176,12 @@ function FlowStep(props) {
|
|||||||
? triggerSubstepsData
|
? triggerSubstepsData
|
||||||
: actionSubstepsData || [];
|
: actionSubstepsData || [];
|
||||||
|
|
||||||
const handleChange = React.useCallback(({ step }) => {
|
const handleChange = React.useCallback(
|
||||||
onChange(step);
|
async ({ step }) => {
|
||||||
}, []);
|
await onChange(step);
|
||||||
|
},
|
||||||
|
[onChange],
|
||||||
|
);
|
||||||
|
|
||||||
const expandNextStep = React.useCallback(() => {
|
const expandNextStep = React.useCallback(() => {
|
||||||
setCurrentSubstep((currentSubstep) => (currentSubstep ?? 0) + 1);
|
setCurrentSubstep((currentSubstep) => (currentSubstep ?? 0) + 1);
|
||||||
|
|||||||
Reference in New Issue
Block a user