From c18cee5d6f1453c8c788cdeec5388c17dbbcff42 Mon Sep 17 00:00:00 2001 From: "a.khmyrov" Date: Tue, 21 Feb 2023 18:35:13 +0100 Subject: [PATCH] fix: add reloading admin data after changes of id --- package.json | 2 +- src/DetailView/RenderDetail.tsx | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 8a0da93fe..b4de498fb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@bestdoctor/ke-beta", - "version": "13.3.0", + "version": "13.3.1", "description": "BestDoctor back-office UI constructor", "author": "pro100filipp", "main": "dist/index.js", diff --git a/src/DetailView/RenderDetail.tsx b/src/DetailView/RenderDetail.tsx index 501c2ab61..8576628ba 100644 --- a/src/DetailView/RenderDetail.tsx +++ b/src/DetailView/RenderDetail.tsx @@ -1,6 +1,6 @@ // Это легаси /* eslint-disable react/jsx-props-no-spreading */ -import React, { useEffect, useRef, useState } from 'react' +import React, { useCallback, useEffect, useRef, useState } from 'react' import { useToast, Box, Spinner, Alert, AlertTitle, AlertIcon, AlertDescription } from '@chakra-ui/react' import { useParams } from 'react-router-dom' import { Row, Col } from 'react-flexbox-grid' @@ -88,13 +88,19 @@ const RenderDetail = (props: RenderDetailProps): JSX.Element => { } setFavicon(favicon) - const refreshMainDetailObject = (): void => { + const refreshMainDetailObject = useCallback(() => { setNeedRefreshDetailObject(true) - } + }, []) + + // update data if id has changed + useEffect(() => { + refreshMainDetailObject() + }, [id, refreshMainDetailObject]) useEffect(() => { - const backendResourceUrl = admin.getResource(id) if (needRefreshDetailObject) { + const backendResourceUrl = admin.getResource(id) + provider .getObject(backendResourceUrl) .then(async (res) => {