diff options
Diffstat (limited to 'packages/merchant-backoffice-ui/src/hooks/templates.ts')
-rw-r--r-- | packages/merchant-backoffice-ui/src/hooks/templates.ts | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/packages/merchant-backoffice-ui/src/hooks/templates.ts b/packages/merchant-backoffice-ui/src/hooks/templates.ts index 3a28b903d..124786887 100644 --- a/packages/merchant-backoffice-ui/src/hooks/templates.ts +++ b/packages/merchant-backoffice-ui/src/hooks/templates.ts @@ -23,7 +23,7 @@ import { HttpResponse, HttpResponseOk, HttpResponsePaginated, -} from "../utils/request.js"; +} from "@gnu-taler/web-util/lib/index.browser"; export function useTemplateAPI(): TemplateAPI { const mutateAll = useMatchMutate(); @@ -79,7 +79,12 @@ export function useTemplateAPI(): TemplateAPI { return res; }; - return { createTemplate, updateTemplate, deleteTemplate, createOrderFromTemplate }; + return { + createTemplate, + updateTemplate, + deleteTemplate, + createOrderFromTemplate, + }; } export interface TemplateAPI { @@ -105,7 +110,10 @@ export interface InstanceTemplateFilter { export function useInstanceTemplates( args?: InstanceTemplateFilter, updatePosition?: (id: string) => void, -): HttpResponsePaginated<MerchantBackend.Template.TemplateSummaryResponse> { +): HttpResponsePaginated< + MerchantBackend.Template.TemplateSummaryResponse, + MerchantBackend.ErrorDetail +> { const { templateFetcher } = useBackendInstanceRequest(); // const [pageBefore, setPageBefore] = useState(1); @@ -140,15 +148,18 @@ export function useInstanceTemplates( isValidating: loadingAfter, } = useSWR< HttpResponseOk<MerchantBackend.Template.TemplateSummaryResponse>, - HttpError + HttpError<MerchantBackend.ErrorDetail> >([`/private/templates`, args?.position, -totalAfter], templateFetcher); //this will save last result // const [lastBefore, setLastBefore] = useState< - // HttpResponse<MerchantBackend.Template.TemplateSummaryResponse> + // HttpResponse<MerchantBackend.Template.TemplateSummaryResponse, MerchantBackend.ErrorDetail> // >({ loading: true }); const [lastAfter, setLastAfter] = useState< - HttpResponse<MerchantBackend.Template.TemplateSummaryResponse> + HttpResponse< + MerchantBackend.Template.TemplateSummaryResponse, + MerchantBackend.ErrorDetail + > >({ loading: true }); useEffect(() => { if (afterData) setLastAfter(afterData); @@ -174,9 +185,10 @@ export function useInstanceTemplates( if (afterData.data.templates.length < MAX_RESULT_SIZE) { setPageAfter(pageAfter + 1); } else { - const from = `${afterData.data.templates[afterData.data.templates.length - 1] - .template_id - }`; + const from = `${ + afterData.data.templates[afterData.data.templates.length - 1] + .template_id + }`; if (from && updatePosition) updatePosition(from); } }, @@ -211,12 +223,15 @@ export function useInstanceTemplates( export function useTemplateDetails( templateId: string, -): HttpResponse<MerchantBackend.Template.TemplateDetails> { +): HttpResponse< + MerchantBackend.Template.TemplateDetails, + MerchantBackend.ErrorDetail +> { const { templateFetcher } = useBackendInstanceRequest(); const { data, error, isValidating } = useSWR< HttpResponseOk<MerchantBackend.Template.TemplateDetails>, - HttpError + HttpError<MerchantBackend.ErrorDetail> >([`/private/templates/${templateId}`], templateFetcher, { refreshInterval: 0, refreshWhenHidden: false, |