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