import React from "react"; import { useTranslate } from "@hooks/i18n"; import type { BaseRecord, HttpError } from "../../contexts/data/types"; import type { AutoSaveIndicatorElements } from "../../hooks/form/types"; import type { UseUpdateReturnType } from "../../hooks/data/useUpdate"; export type AutoSaveIndicatorProps< TData extends BaseRecord = BaseRecord, TError extends HttpError = HttpError, TVariables = {}, > = { /** * The data returned by the update request. */ data?: UseUpdateReturnType["mutation"]["data"]; /** * The error returned by the update request. */ error?: UseUpdateReturnType["mutation"]["error"]; /** * The status of the update request. */ status: UseUpdateReturnType["mutation"]["status"]; /** * The elements to display for each status. */ elements?: AutoSaveIndicatorElements; }; export const AutoSaveIndicator: React.FC = ({ status, elements: { success = ( ), error = ( ), loading = ( ), idle = ( ), } = {}, }) => { switch (status) { case "success": return <>{success}; case "error": return <>{error}; case "pending": return <>{loading}; case "idle": return <>{idle}; default: return <>{idle}; } }; const Message = ({ translationKey, defaultMessage, }: { translationKey: string; defaultMessage: string; }) => { const translate = useTranslate(); return {translate(translationKey, defaultMessage)}; };