Skip to content

Commit

Permalink
♻️ refactor(mutations): clean up types
Browse files Browse the repository at this point in the history
thrownullexception committed Aug 7, 2024
1 parent b4591d6 commit 5a48dee
Showing 3 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -127,3 +127,4 @@ export function RenderFormInput(props: IRenderFormInputProps) {
}
}
// TODO: Rating Input (for contributors)
// sliders
16 changes: 0 additions & 16 deletions src/frontend/lib/data/useMutate/types.d.ts

This file was deleted.

17 changes: 16 additions & 1 deletion src/frontend/lib/data/useMutate/useApiMutateOptimisticOptions.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { MessageDescriptor } from "@lingui/core";
import { msg } from "@lingui/macro";
import { useMutation, useQueryClient } from "@tanstack/react-query";

@@ -6,7 +7,21 @@ import { noop } from "@/shared/lib/noop";
import { fakeMessageDescriptor } from "@/translations/fake";

import { getQueryCachekey } from "../constants/getQueryCacheKey";
import type { IApiMutateOptions } from "./types";

export type ToastMessageInput = {
description: MessageDescriptor;
// action?: { label: MessageDescriptor; action: () => void };
};

export interface IApiMutateOptions<T, V, R> {
dataQueryPath: string;
otherEndpoints?: string[];
onMutate: (oldData: T | undefined, form: V) => T;
mutationFn: (form: V) => Promise<R>;
successMessage?: ToastMessageInput;
smartSuccessMessage?: (formData: R) => ToastMessageInput;
onSuccessActionWithFormData?: (formData: R) => void;
}

function useApiMutate<T>(endpoint: string) {
const queryClient = useQueryClient();

0 comments on commit 5a48dee

Please sign in to comment.