From 5fe651d5176d4453c88ae5038d15137205814071 Mon Sep 17 00:00:00 2001 From: Nastya Date: Thu, 4 Jan 2024 13:20:14 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B8=D1=82=D0=BE=D1=80=D0=B8=D1=8F=20=D0=BF?= =?UTF-8?q?=D1=80=D0=B8=D0=B2=D0=BE=D0=B4=D0=B8=D1=82=D1=81=D1=8F=20=D0=BA?= =?UTF-8?q?=20=D0=B2=D0=B8=D0=B4=D1=83=20=D0=B2=20=D0=B4=D0=B5=D1=82=D0=B0?= =?UTF-8?q?=D0=BB=D1=81=20-=20=D1=81=D0=BD=D0=B0=D1=87=D0=B0=D0=BB=D0=B0?= =?UTF-8?q?=20=D1=82=D0=B0=D1=80=D0=B8=D1=84=20-=20=D0=BF=D0=BE=D1=82?= =?UTF-8?q?=D0=BE=D0=BC=20=D0=BF=D1=80=D0=B0=D0=B9=D1=81.=20=D0=BE=D0=B1?= =?UTF-8?q?=D0=B5=D1=89=D0=B0=D0=BB=D0=B8=20=D0=B1=D0=BE=D0=BB=D1=8C=D1=88?= =?UTF-8?q?=D0=B5=20=D0=B2=20=D0=B4=D0=B5=D1=82=D0=B0=D0=BB=D1=81=20=D1=8D?= =?UTF-8?q?=D0=BB=D0=B5=D0=BC=D0=B5=D0=BD=D1=82=D0=BE=D0=B2=20=D0=BD=D0=B5?= =?UTF-8?q?=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D1=8F=D1=82=D1=8C.=20?= =?UTF-8?q?=D0=B2=20=D1=80=D0=B0=D0=BD=D0=B5=D0=B5=20=D0=B2=D1=8B=20=D1=8B?= =?UTF-8?q?=D1=81=D1=82=D0=B0=D0=B2=D0=BB=D1=8F=D0=B5=D1=82=D1=81=D1=8F=20?= =?UTF-8?q?10=20=D1=82=D0=B0=D1=80=D0=B8=D1=84=D0=BE=D0=B2,=20=D0=BD=D0=B5?= =?UTF-8?q?=20=D0=B1=D0=BE=D0=BB=D0=B5=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/history.ts | 43 ++++++++++++++----- src/api/wallet.ts | 3 +- src/pages/Payment/Payment.tsx | 20 ++++++--- src/pages/Tariffs/TariffsPage.tsx | 1 + .../hooks/useRecentlyPurchasedTariffs.ts | 10 +++-- 5 files changed, 57 insertions(+), 20 deletions(-) diff --git a/src/api/history.ts b/src/api/history.ts index 95a8efe..243c6f4 100644 --- a/src/api/history.ts +++ b/src/api/history.ts @@ -2,24 +2,29 @@ import { Tariff, makeRequest } from "@frontend/kitui" import { parseAxiosError } from "@root/utils/parse-error" export interface GetHistoryResponse { - totalPages: number; - records: HistoryRecord[]; + totalPages: number; + records: HistoryRecord[]; } export type HistoryRecord = { - comment: string; - createdAt: string; - id: string; - isDeleted: boolean; - key: string; - rawDetails: [RawDetails, KeyValue]; - updatedAt: string; - userId: string; + comment: string; + createdAt: string; + id: string; + isDeleted: boolean; + key: string; + rawDetails: [RawDetails, KeyValue]; + updatedAt: string; + userId: string; }; type RawDetails = { Key: string; Value: KeyValue[][] } type KeyValue = { Key: string; Value: string | number }; +const regList:Record = { + "tariffs": 0, + "price": 1 +} + export async function getHistory(): Promise<[GetHistoryResponse | null, string?]> { try { const historyResponse = await makeRequest({ @@ -28,6 +33,24 @@ export async function getHistory(): Promise<[GetHistoryResponse | null, string?] useToken: true, }) + const checked = historyResponse.records.map((data) => { + console.log(data.rawDetails) + const buffer:KeyValue[] = [] + data.rawDetails.forEach((slot) => { + let index = regList[slot.Key as string] + //@ts-ignore + buffer[index] = { Key: slot.Key, Value: slot.Value } + }) + //Чистим дыры с помощью .filter(() => true) но нужно ли это + console.log("Я собираюсь вкладывать такой буфер равдетайлс", buffer) + //@ts-ignore + data.rawDetails = buffer + return data + }) + + + historyResponse.records = checked || [] +console.log("historyResponse ", historyResponse) return [historyResponse] } catch (nativeError) { const [error] = parseAxiosError(nativeError) diff --git a/src/api/wallet.ts b/src/api/wallet.ts index ba7d5cb..74859dc 100644 --- a/src/api/wallet.ts +++ b/src/api/wallet.ts @@ -24,8 +24,9 @@ const testPaymentBody: SendPaymentRequest = { } export async function sendPayment( - body: SendPaymentRequest = testPaymentBody + {body = testPaymentBody, fromSquiz = false}: {body?: SendPaymentRequest, fromSquiz:boolean} ): Promise<[SendPaymentResponse | null, string?]> { + if (fromSquiz) body.returnUrl = "squiz.pena.digital/list?action=fromhub" try { const sendPaymentResponse = await makeRequest< SendPaymentRequest, diff --git a/src/pages/Payment/Payment.tsx b/src/pages/Payment/Payment.tsx index 56999d8..da6732d 100644 --- a/src/pages/Payment/Payment.tsx +++ b/src/pages/Payment/Payment.tsx @@ -15,13 +15,13 @@ import qiwiLogo from "../../assets/bank-logo/logo-qiwi.png" import mirLogo from "../../assets/bank-logo/logo-mir.png" import tinkoffLogo from "../../assets/bank-logo/logo-tinkoff.png" import { cardShadow } from "@root/utils/theme" -import { useEffect, useState } from "react" +import { useEffect, useLayoutEffect, useState } from "react" import InputTextfield from "@root/components/InputTextfield" import { sendPayment } from "@root/api/wallet" import { getMessageFromFetchError } from "@frontend/kitui" import { enqueueSnackbar } from "notistack" import { currencyFormatter } from "@root/utils/currencyFormatter" -import { useLocation } from "react-router-dom" +import { useLocation, useNavigate } from "react-router-dom" import { useHistoryTracker } from "@root/utils/hooks/useHistoryTracker" const paymentMethods = [ @@ -44,16 +44,24 @@ export default function Payment() { useState(null) const [paymentValueField, setPaymentValueField] = useState("0") const [paymentLink, setPaymentLink] = useState("") + const [fromSquiz, setIsFromSquiz] = useState(false) const location = useLocation() const notEnoughMoneyAmount = (location.state?.notEnoughMoneyAmount as number) ?? 0 const paymentValue = parseFloat(paymentValueField) * 100 - - useEffect(() => { - setPaymentValueField((notEnoughMoneyAmount / 100).toString()) + + useLayoutEffect(() => { // eslint-disable-next-line react-hooks/exhaustive-deps + setPaymentValueField((notEnoughMoneyAmount / 100).toString()) + const params = new URLSearchParams(window.location.search) + const fromSquiz = params.get("action") + if (fromSquiz === "squizpay") { + setIsFromSquiz(true) + setPaymentValueField(params.get("dif") || "0") + } + console.log(fromSquiz) }, []) useEffect(() => { @@ -62,7 +70,7 @@ export default function Payment() { async function handleChoosePaymentClick() { if (Number(paymentValueField) !== 0) { - const [sendPaymentResponse, sendPaymentError] = await sendPayment() + const [sendPaymentResponse, sendPaymentError] = await sendPayment({fromSquiz}) if (sendPaymentError) { return enqueueSnackbar(sendPaymentError) diff --git a/src/pages/Tariffs/TariffsPage.tsx b/src/pages/Tariffs/TariffsPage.tsx index 4c73d15..9fb9291 100644 --- a/src/pages/Tariffs/TariffsPage.tsx +++ b/src/pages/Tariffs/TariffsPage.tsx @@ -132,6 +132,7 @@ function TariffPage() { return tariffElements; }; + console.log(recentlyPurchased) return ( { const tariffs = useTariffStore((state) => state.tariffs); const historyData = useHistoryStore(state => state.history); useEffect(() => { + console.log("юзэффект начинает работаььб") async function fetchData() { try { const [response, errorMsg] = await getRecentlyPurchasedTariffs(); - +console.log("responce" , response) if (errorMsg) { console.error("Произошла ошибка при вызове getRecentlyPurchasedTariffs:", errorMsg); } if (response) { - const recentlyTariffs = response.map((obj: { id: string })=>obj.id) + const recentlyTariffs = response.slice(0, 10).map((obj: { id: string })=>obj.id) + console.log("responce22222222222222222" , recentlyTariffs) + console.log("tariffstariffstariffstariffstariffstariffs" , tariffs) setRecentlyPurchased(tariffs.filter((tariffs)=>{ return recentlyTariffs.includes(tariffs._id)})); } @@ -27,6 +30,7 @@ export const useRecentlyPurchasedTariffs = () => { } fetchData(); - }, []); + }, [tariffs]); + console.log(recentlyPurchased) return {recentlyPurchased} } \ No newline at end of file