From 11079902f5147b37870f8e40f4815dbb6fe904a8 Mon Sep 17 00:00:00 2001 From: Valentyna Dudchak Date: Wed, 16 Oct 2024 21:18:00 +0300 Subject: [PATCH] fixed updating offer data --- .../complete-profile/CompleteProfileBlock.tsx | 16 +++++++++++++++- src/components/profile-item/ProfileItem.tsx | 17 ++++------------- .../offer-page/create-offer/CreateOffer.tsx | 16 +++++++++++++--- .../create-or-edit-offer/CreateOrEditOffer.tsx | 9 ++++++--- 4 files changed, 38 insertions(+), 20 deletions(-) diff --git a/src/components/complete-profile/CompleteProfileBlock.tsx b/src/components/complete-profile/CompleteProfileBlock.tsx index e7a0c4247..26222953e 100644 --- a/src/components/complete-profile/CompleteProfileBlock.tsx +++ b/src/components/complete-profile/CompleteProfileBlock.tsx @@ -24,6 +24,9 @@ import { styles } from '~/components/complete-profile/CompleteProfileBlock.style import useAxios from '~/hooks/use-axios' import { OfferService } from '~/services/offer-service' import { defaultResponse } from '~/pages/my-offers/MyOffers.constants' +import { useDrawer } from '~/hooks/use-drawer' +import AppDrawer from '~/components/app-drawer/AppDrawer' +import CreateOffer from '~/containers/offer-page/create-offer/CreateOffer' interface CompleteProfileBlockProps { profileItems: ProfileItemType[] @@ -42,6 +45,10 @@ const CompleteProfileBlock: FC = ({ const homePage = useMatch(guestRoutes[userRole as UserRole].path) const [isOpen, setIsOpen] = useState(false) + const { openDrawer, closeDrawer, isOpen: isDrawerOpen } = useDrawer() + const [isOfferCreated, setIsOfferCreated] = useState(false) + const handleOpenDrawer = () => openDrawer() + useEffect(() => { if (openAccordion) { setIsOpen(true) @@ -53,7 +60,7 @@ const CompleteProfileBlock: FC = ({ OfferService.getUsersOffers({ id: userId }), - [userId] + [userId, isOfferCreated] ) const { response } = useAxios({ @@ -99,6 +106,7 @@ const CompleteProfileBlock: FC = ({ () => profileItems.map((item) => ( = ({ {profileList} + + + ) diff --git a/src/components/profile-item/ProfileItem.tsx b/src/components/profile-item/ProfileItem.tsx index fefb2e32e..497d2096a 100644 --- a/src/components/profile-item/ProfileItem.tsx +++ b/src/components/profile-item/ProfileItem.tsx @@ -8,29 +8,25 @@ import { styles } from '~/components/profile-item/ProfileItem.styles' import useBreakpoints from '~/hooks/use-breakpoints' import { ProfileItemType } from '~/components/profile-item/complete-profile.constants' import { UserRoleEnum } from '~/types' -import CreateOffer from '~/containers/offer-page/create-offer/CreateOffer' -import { useDrawer } from '~/hooks/use-drawer' -import AppDrawer from '~/components/app-drawer/AppDrawer' interface ProfileItemProps { item: ProfileItemType isFilled?: boolean userRole: UserRoleEnum | '' + handleOpenDrawer?: () => void | undefined } const ProfileItem = ({ item, userRole, - isFilled = false + isFilled = false, + handleOpenDrawer = undefined }: ProfileItemProps) => { const { t } = useTranslation() const { isMobile } = useBreakpoints() const { id, icon } = item const navigate = useNavigate() - const { openDrawer, closeDrawer, isOpen } = useDrawer() - const handleOpenDrawer = () => openDrawer() - const isClickable = !isFilled && item.id !== 'schedule' const isOffer = item.id === 'offer' @@ -39,7 +35,7 @@ const ProfileItem = ({ navigate(`${item.path}#${item.id}`) } if (isOffer) { - handleOpenDrawer() + handleOpenDrawer!() } } @@ -64,11 +60,6 @@ const ProfileItem = ({ - {isOffer && ( - - - - )} {isFilled && ( void + updateOffer?: Dispatch> | undefined } -const CreateOffer: FC = ({ closeDrawer }) => { +const CreateOffer: FC = ({ + closeDrawer, + updateOffer = undefined +}) => { const postOffer = useCallback( (data: CreateOrUpdateOfferData) => OfferService.createOffer({ ...data, FAQ: findFullObjects(data.FAQ) }), [] ) - return + return ( + + ) } export default CreateOffer diff --git a/src/containers/offer-page/create-or-edit-offer/CreateOrEditOffer.tsx b/src/containers/offer-page/create-or-edit-offer/CreateOrEditOffer.tsx index 345648da3..891871a2c 100644 --- a/src/containers/offer-page/create-or-edit-offer/CreateOrEditOffer.tsx +++ b/src/containers/offer-page/create-or-edit-offer/CreateOrEditOffer.tsx @@ -1,4 +1,4 @@ -import { FC, useEffect } from 'react' +import { FC, useEffect, Dispatch, SetStateAction } from 'react' import { useTranslation } from 'react-i18next' import { useNavigate, useLocation } from 'react-router-dom' import LeakAddSharpIcon from '@mui/icons-material/LeakAddSharp' @@ -38,15 +38,17 @@ import { openAlert } from '~/redux/features/snackbarSlice' import { getErrorKey } from '~/utils/get-error-key' interface CreateOrUpdateOfferProps { - existingOffer: Offer | null + existingOffer?: Offer | null closeDrawer: () => void service: ServiceFunction + updateOffer?: Dispatch> | undefined } const CreateOrEditOffer: FC = ({ existingOffer = null, closeDrawer, - service + service, + updateOffer = undefined }) => { const { userRole } = useAppSelector((state) => state.appMain) const { setNeedConfirmation } = useConfirm() @@ -77,6 +79,7 @@ const CreateOrEditOffer: FC = ({ closeDrawer() if (hash == '#offer') { navigate(`${authRoutes.myProfile.path}#complete`) + updateOffer!(true) } else { navigate( createUrlPath(