From e45b9d1aff92bac2730f34f9e87b18da7145bd3c Mon Sep 17 00:00:00 2001 From: Mikhail Mogilnikov Date: Mon, 24 Jun 2024 13:59:52 +0300 Subject: [PATCH] fix: billing auth, location in home page --- .../billing/api/send-payment-request.ts | 21 ++++++++++++------- src/page/personal/billing/ui/billing-form.tsx | 3 +++ .../public/home/ui/ads-list/ads-container.tsx | 13 +++++------- src/page/public/home/ui/ads-list/index.tsx | 9 ++++++-- .../public/home/ui/ads-list/placeholder.tsx | 21 +++++++++++++++++++ .../modal/ui/variants/location/index.tsx | 7 +++++++ .../ui/ads-infinite-scroller.tsx | 14 ++++++++++++- 7 files changed, 69 insertions(+), 19 deletions(-) create mode 100644 src/page/public/home/ui/ads-list/placeholder.tsx diff --git a/src/page/personal/billing/api/send-payment-request.ts b/src/page/personal/billing/api/send-payment-request.ts index db2ef41..a1f2c03 100644 --- a/src/page/personal/billing/api/send-payment-request.ts +++ b/src/page/personal/billing/api/send-payment-request.ts @@ -7,12 +7,17 @@ export const sendPaymentRequest = ( name: string, phone: string, isSaveData: boolean, + token: string, ) => - paymentClient.post('bill/', { - amount, - cryptogram, - email, - name, - phone, - isSaveData, - }); + paymentClient.post( + 'bill/', + { + amount, + cryptogram, + email, + name, + phone, + isSaveData, + }, + { Authorization: `Bearer ${token}` }, + ); diff --git a/src/page/personal/billing/ui/billing-form.tsx b/src/page/personal/billing/ui/billing-form.tsx index d687bde..c3a59f6 100644 --- a/src/page/personal/billing/ui/billing-form.tsx +++ b/src/page/personal/billing/ui/billing-form.tsx @@ -15,6 +15,7 @@ import { PaymentWidget } from '@albomoni/widgets/payment-widget'; import { useSession } from '@albomoni/shared/lib/hooks/use-session'; import { Spinner } from '@nextui-org/spinner'; import { useCurrencies } from '@albomoni/shared/lib/providers/currencies-provider'; +import { getCookie } from 'cookies-next'; import { BillingSchema } from '../model/schema'; import { sendPaymentRequest } from '../api/send-payment-request'; @@ -28,6 +29,7 @@ export const BillingForm = () => { const router = useRouter(); const { user } = useSession(); const currencies = useCurrencies(); + const token = getCookie('token'); const [isSave, setIsSave] = useState(false); const [isLoading, setIsLoading] = useState(false); @@ -86,6 +88,7 @@ export const BillingForm = () => { data.cardholder, data.tel, isSave, + token, ); router.push(response as string); diff --git a/src/page/public/home/ui/ads-list/ads-container.tsx b/src/page/public/home/ui/ads-list/ads-container.tsx index c338414..ad7b58c 100644 --- a/src/page/public/home/ui/ads-list/ads-container.tsx +++ b/src/page/public/home/ui/ads-list/ads-container.tsx @@ -2,10 +2,9 @@ import { AdsInfiniteScroller } from '@albomoni/widgets/infinite-scroller'; import { useState } from 'react'; -import { Placeholder } from '@albomoni/shared/ui/placeholder'; -import { PiMagnifyingGlass } from 'react-icons/pi'; import { getLocation } from '@albomoni/shared/lib/utils/get-location'; import { fetchAds } from '../../api/get-ads/fetch-ads'; +import { HomeAdsPlaceholder } from './placeholder'; export const AdsContainer = ({ currencies, @@ -15,18 +14,16 @@ export const AdsContainer = ({ const [isAds, setIsAds] = useState(true); const location = getLocation(); + console.log(location) + return isAds ? ( ) : ( - } - title='Объявления не найдены' - desc='Создайте первое объявление в своём городе!' - /> + ); }; diff --git a/src/page/public/home/ui/ads-list/index.tsx b/src/page/public/home/ui/ads-list/index.tsx index 3d8af7b..3df7002 100644 --- a/src/page/public/home/ui/ads-list/index.tsx +++ b/src/page/public/home/ui/ads-list/index.tsx @@ -1,5 +1,10 @@ import { getCurrenciesAsync } from '@albomoni/entities/ad-card/api/get-currencies'; -import { AdsContainer } from './ads-container'; +import dynamic from 'next/dynamic'; + +const DynamicAdsContainer = dynamic( + () => import('./ads-container').then((mod) => mod.AdsContainer), + { ssr: false }, +); export const HomeAdsList = async ({ lng }: { lng: string }) => { const currencies = await getCurrenciesAsync(); @@ -7,7 +12,7 @@ export const HomeAdsList = async ({ lng }: { lng: string }) => { return (

Актуальные объявления

- +
); }; diff --git a/src/page/public/home/ui/ads-list/placeholder.tsx b/src/page/public/home/ui/ads-list/placeholder.tsx new file mode 100644 index 0000000..0ecf1c2 --- /dev/null +++ b/src/page/public/home/ui/ads-list/placeholder.tsx @@ -0,0 +1,21 @@ +import { getLocation } from '@albomoni/shared/lib/utils/get-location'; +import { Placeholder } from '@albomoni/shared/ui/placeholder'; +import { PiCompass, PiMagnifyingGlass } from 'react-icons/pi'; + +export const HomeAdsPlaceholder = () => { + const location = getLocation(); + + return location.address === 'Весь мир' ? ( + } + title='Не выбран регион' + desc='Перейдите в выбор региона для уточнения зоны поиска объявлений' + /> + ) : ( + } + title='Объявления не найдены' + desc='Создайте первое объявление в своём городе!' + /> + ); +}; diff --git a/src/shared/lib/providers/modal/ui/variants/location/index.tsx b/src/shared/lib/providers/modal/ui/variants/location/index.tsx index dfad2a1..72ca4fc 100644 --- a/src/shared/lib/providers/modal/ui/variants/location/index.tsx +++ b/src/shared/lib/providers/modal/ui/variants/location/index.tsx @@ -2,6 +2,7 @@ import { Button } from '@nextui-org/button'; import { PiCheckBold, PiMapPinBold, PiPencilSimpleBold } from 'react-icons/pi'; import Link from 'next/link'; import { getLocation } from '@albomoni/shared/lib/utils/get-location'; +import { useEffect } from 'react'; import { ModalScrollableArea } from '../../scrollable-area'; import { useModal } from '../../../lib/use-modal'; import { EModalStates } from '../../../model/modal-states.enum'; @@ -10,6 +11,12 @@ export const ModalVariantLocation = () => { const { setModalState } = useModal(); const location = getLocation(); + useEffect(() => { + return () => { + window.location.reload(); + }; + }, []); + return ( <> diff --git a/src/widgets/infinite-scroller/ui/ads-infinite-scroller.tsx b/src/widgets/infinite-scroller/ui/ads-infinite-scroller.tsx index 8186677..0093dc0 100644 --- a/src/widgets/infinite-scroller/ui/ads-infinite-scroller.tsx +++ b/src/widgets/infinite-scroller/ui/ads-infinite-scroller.tsx @@ -1,3 +1,5 @@ +/* eslint-disable sonarjs/cognitive-complexity */ + 'use client'; import { Ad } from '@albomoni/entities/ad-card/model/ad.type'; @@ -5,6 +7,9 @@ import { AdCard } from '@albomoni/entities/ad-card/ui/ad-card'; import { useEffect, useRef, useState } from 'react'; import { useIntersection } from 'react-use'; import { useQuery } from '@tanstack/react-query'; +import { getLocation } from '@albomoni/shared/lib/utils/get-location'; +import { Placeholder } from '@albomoni/shared/ui/placeholder'; +import { PiCompass } from 'react-icons/pi'; import { AdsSkeleton } from './ads-skeleton'; type Props = { @@ -27,6 +32,7 @@ export const AdsInfiniteScroller = ({ const [ads, setAds] = useState([]); const [isEnded, setIsEnded] = useState(true); const intersectionRef = useRef(null); + const location = getLocation(); const { data, isLoading, refetch } = useQuery({ queryKey: [queryKey, page], @@ -69,7 +75,7 @@ export const AdsInfiniteScroller = ({ } }, [intersection]); - return ( + return location.address !== 'Весь мир' ? ( <>
{ads.map((ad) => { @@ -87,5 +93,11 @@ export const AdsInfiniteScroller = ({ {!isEnded &&
} + ) : ( + } + title='Не выбран регион' + desc='Перейдите в выбор региона для уточнения зоны поиска объявлений' + /> ); };