итория приводится к виду в деталс - сначала тариф - потом прайс. обещали больше в деталс элементов не добавлять. в ранее вы ыставляется 10 тарифов, не более

This commit is contained in:
Nastya 2024-01-04 13:20:14 +03:00
parent 9d1b23b96f
commit 5fe651d517
5 changed files with 57 additions and 20 deletions

@ -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<string, number> = {
"tariffs": 0,
"price": 1
}
export async function getHistory(): Promise<[GetHistoryResponse | null, string?]> {
try {
const historyResponse = await makeRequest<never, GetHistoryResponse>({
@ -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)

@ -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,

@ -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<PaymentMethod | null>(null)
const [paymentValueField, setPaymentValueField] = useState<string>("0")
const [paymentLink, setPaymentLink] = useState<string>("")
const [fromSquiz, setIsFromSquiz] = useState<boolean>(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)

@ -132,6 +132,7 @@ function TariffPage() {
return tariffElements;
};
console.log(recentlyPurchased)
return (
<SectionWrapper
maxWidth="lg"

@ -9,15 +9,18 @@ export const useRecentlyPurchasedTariffs = () => {
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}
}