Skip to content

Commit

Permalink
fix: billing auth, location in home page
Browse files Browse the repository at this point in the history
  • Loading branch information
mikhailmogilnikov committed Jun 24, 2024
1 parent 707104b commit e45b9d1
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 19 deletions.
21 changes: 13 additions & 8 deletions src/page/personal/billing/api/send-payment-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}` },
);
3 changes: 3 additions & 0 deletions src/page/personal/billing/ui/billing-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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);
Expand Down Expand Up @@ -86,6 +88,7 @@ export const BillingForm = () => {
data.cardholder,
data.tel,
isSave,
token,
);

router.push(response as string);
Expand Down
13 changes: 5 additions & 8 deletions src/page/public/home/ui/ads-list/ads-container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -15,18 +14,16 @@ export const AdsContainer = ({
const [isAds, setIsAds] = useState(true);
const location = getLocation();

console.log(location)

return isAds ? (
<AdsInfiniteScroller
setIsAds={setIsAds}
currencies={currencies}
fetchFunc={fetchAds}
queryKey={`home-scroll_${location.lat}_${location.lon}`}
queryKey={`home-scroll_${location.address}_${location.lon}`}
/>
) : (
<Placeholder
icon={<PiMagnifyingGlass size={64} className='opacity-50 mt-10' />}
title='Объявления не найдены'
desc='Создайте первое объявление в своём городе!'
/>
<HomeAdsPlaceholder />
);
};
9 changes: 7 additions & 2 deletions src/page/public/home/ui/ads-list/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
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();

return (
<div className='w-full h-min flex flex-col gap-6'>
<h2 className='text-xl md:text-2xl font-bold'>Актуальные объявления</h2>
<AdsContainer currencies={currencies} />
<DynamicAdsContainer currencies={currencies} />
</div>
);
};
21 changes: 21 additions & 0 deletions src/page/public/home/ui/ads-list/placeholder.tsx
Original file line number Diff line number Diff line change
@@ -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 === 'Весь мир' ? (
<Placeholder
icon={<PiCompass size={64} className='opacity-50 mt-10' />}
title='Не выбран регион'
desc='Перейдите в выбор региона для уточнения зоны поиска объявлений'
/>
) : (
<Placeholder
icon={<PiMagnifyingGlass size={64} className='opacity-50 mt-10' />}
title='Объявления не найдены'
desc='Создайте первое объявление в своём городе!'
/>
);
};
7 changes: 7 additions & 0 deletions src/shared/lib/providers/modal/ui/variants/location/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -10,6 +11,12 @@ export const ModalVariantLocation = () => {
const { setModalState } = useModal();
const location = getLocation();

useEffect(() => {
return () => {
window.location.reload();
};
}, []);

return (
<>
<ModalScrollableArea>
Expand Down
14 changes: 13 additions & 1 deletion src/widgets/infinite-scroller/ui/ads-infinite-scroller.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
/* eslint-disable sonarjs/cognitive-complexity */

'use client';

import { Ad } from '@albomoni/entities/ad-card/model/ad.type';
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 = {
Expand All @@ -27,6 +32,7 @@ export const AdsInfiniteScroller = ({
const [ads, setAds] = useState<Ad[]>([]);
const [isEnded, setIsEnded] = useState(true);
const intersectionRef = useRef(null);
const location = getLocation();

const { data, isLoading, refetch } = useQuery({
queryKey: [queryKey, page],
Expand Down Expand Up @@ -69,7 +75,7 @@ export const AdsInfiniteScroller = ({
}
}, [intersection]);

return (
return location.address !== 'Весь мир' ? (
<>
<div className='w-full grid md:grid-cols-2 lg:grid-cols-3 gap-8'>
{ads.map((ad) => {
Expand All @@ -87,5 +93,11 @@ export const AdsInfiniteScroller = ({

{!isEnded && <div ref={intersectionRef} />}
</>
) : (
<Placeholder
icon={<PiCompass size={60} className='mt-10' />}
title='Не выбран регион'
desc='Перейдите в выбор региона для уточнения зоны поиска объявлений'
/>
);
};

0 comments on commit e45b9d1

Please sign in to comment.