Update counter only on success
Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
@@ -144,8 +144,10 @@ export default function TaskFormDialog(props: Props) {
|
||||
},
|
||||
connections: [props.connection!],
|
||||
},
|
||||
onCompleted: () => {
|
||||
updateStoreCounter(relayEnv, data.measureId, "tasks(first:0)", 1);
|
||||
onCompleted: (_response, errors) => {
|
||||
if (!errors) {
|
||||
updateStoreCounter(relayEnv, data.measureId, "tasks(first:0)", 1);
|
||||
}
|
||||
},
|
||||
});
|
||||
reset();
|
||||
|
||||
@@ -165,8 +165,8 @@ function TaskRow(props: TaskRowProps) {
|
||||
input: { taskId: props.task.id },
|
||||
connections: [props.connectionId],
|
||||
},
|
||||
onCompleted: () => {
|
||||
if (params.measureId) {
|
||||
onCompleted: (_response, errors) => {
|
||||
if (!errors && params.measureId) {
|
||||
updateStoreCounter(
|
||||
relayEnv,
|
||||
params.measureId,
|
||||
|
||||
@@ -6,10 +6,10 @@ import {
|
||||
} from "react-relay";
|
||||
import {
|
||||
commitLocalUpdate,
|
||||
type Environment,
|
||||
type GraphQLTaggedNode,
|
||||
type MutationParameters,
|
||||
} from "relay-runtime";
|
||||
import type RelayModernEnvironment from "relay-runtime/lib/store/RelayModernEnvironment";
|
||||
|
||||
const defaultOptions = {
|
||||
field: "totalCount",
|
||||
@@ -36,13 +36,15 @@ export function useMutationWithIncrement<T extends MutationParameters>(
|
||||
return mutate({
|
||||
...queryOptions,
|
||||
onCompleted: (response, error) => {
|
||||
updateStoreCounter(
|
||||
relayEnv,
|
||||
options.id,
|
||||
options.node,
|
||||
options.value,
|
||||
options.field,
|
||||
);
|
||||
if (!error) {
|
||||
updateStoreCounter(
|
||||
relayEnv,
|
||||
options.id,
|
||||
options.node,
|
||||
options.value,
|
||||
options.field,
|
||||
);
|
||||
}
|
||||
queryOptions.onCompleted?.(response, error);
|
||||
},
|
||||
});
|
||||
@@ -54,7 +56,7 @@ export function useMutationWithIncrement<T extends MutationParameters>(
|
||||
}
|
||||
|
||||
export function updateStoreCounter(
|
||||
relayEnv: RelayModernEnvironment,
|
||||
relayEnv: Environment,
|
||||
recordId: string,
|
||||
nodeName: string,
|
||||
value: number = 1,
|
||||
|
||||
@@ -180,13 +180,15 @@ function EvidenceRow(props: {
|
||||
evidenceId: evidence.id,
|
||||
},
|
||||
},
|
||||
onCompleted: () => {
|
||||
updateStoreCounter(
|
||||
relayEnv,
|
||||
props.measureId,
|
||||
"evidences(first:0)",
|
||||
-1
|
||||
);
|
||||
onCompleted: (_response, errors) => {
|
||||
if (!errors) {
|
||||
updateStoreCounter(
|
||||
relayEnv,
|
||||
props.measureId,
|
||||
"evidences(first:0)",
|
||||
-1
|
||||
);
|
||||
}
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user