итория приводится к виду в деталс - сначала тариф - потом прайс. обещали больше в деталс элементов не добавлять. в ранее вы ыставляется 10 тарифов, не более
This commit is contained in:
parent
9d1b23b96f
commit
5fe651d517
@ -2,24 +2,29 @@ import { Tariff, makeRequest } from "@frontend/kitui"
|
|||||||
import { parseAxiosError } from "@root/utils/parse-error"
|
import { parseAxiosError } from "@root/utils/parse-error"
|
||||||
|
|
||||||
export interface GetHistoryResponse {
|
export interface GetHistoryResponse {
|
||||||
totalPages: number;
|
totalPages: number;
|
||||||
records: HistoryRecord[];
|
records: HistoryRecord[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export type HistoryRecord = {
|
export type HistoryRecord = {
|
||||||
comment: string;
|
comment: string;
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
id: string;
|
id: string;
|
||||||
isDeleted: boolean;
|
isDeleted: boolean;
|
||||||
key: string;
|
key: string;
|
||||||
rawDetails: [RawDetails, KeyValue];
|
rawDetails: [RawDetails, KeyValue];
|
||||||
updatedAt: string;
|
updatedAt: string;
|
||||||
userId: string;
|
userId: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
type RawDetails = { Key: string; Value: KeyValue[][] }
|
type RawDetails = { Key: string; Value: KeyValue[][] }
|
||||||
type KeyValue = { Key: string; Value: string | number };
|
type KeyValue = { Key: string; Value: string | number };
|
||||||
|
|
||||||
|
const regList:Record<string, number> = {
|
||||||
|
"tariffs": 0,
|
||||||
|
"price": 1
|
||||||
|
}
|
||||||
|
|
||||||
export async function getHistory(): Promise<[GetHistoryResponse | null, string?]> {
|
export async function getHistory(): Promise<[GetHistoryResponse | null, string?]> {
|
||||||
try {
|
try {
|
||||||
const historyResponse = await makeRequest<never, GetHistoryResponse>({
|
const historyResponse = await makeRequest<never, GetHistoryResponse>({
|
||||||
@ -28,6 +33,24 @@ export async function getHistory(): Promise<[GetHistoryResponse | null, string?]
|
|||||||
useToken: true,
|
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]
|
return [historyResponse]
|
||||||
} catch (nativeError) {
|
} catch (nativeError) {
|
||||||
const [error] = parseAxiosError(nativeError)
|
const [error] = parseAxiosError(nativeError)
|
||||||
|
@ -24,8 +24,9 @@ const testPaymentBody: SendPaymentRequest = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function sendPayment(
|
export async function sendPayment(
|
||||||
body: SendPaymentRequest = testPaymentBody
|
{body = testPaymentBody, fromSquiz = false}: {body?: SendPaymentRequest, fromSquiz:boolean}
|
||||||
): Promise<[SendPaymentResponse | null, string?]> {
|
): Promise<[SendPaymentResponse | null, string?]> {
|
||||||
|
if (fromSquiz) body.returnUrl = "squiz.pena.digital/list?action=fromhub"
|
||||||
try {
|
try {
|
||||||
const sendPaymentResponse = await makeRequest<
|
const sendPaymentResponse = await makeRequest<
|
||||||
SendPaymentRequest,
|
SendPaymentRequest,
|
||||||
|
@ -15,13 +15,13 @@ import qiwiLogo from "../../assets/bank-logo/logo-qiwi.png"
|
|||||||
import mirLogo from "../../assets/bank-logo/logo-mir.png"
|
import mirLogo from "../../assets/bank-logo/logo-mir.png"
|
||||||
import tinkoffLogo from "../../assets/bank-logo/logo-tinkoff.png"
|
import tinkoffLogo from "../../assets/bank-logo/logo-tinkoff.png"
|
||||||
import { cardShadow } from "@root/utils/theme"
|
import { cardShadow } from "@root/utils/theme"
|
||||||
import { useEffect, useState } from "react"
|
import { useEffect, useLayoutEffect, useState } from "react"
|
||||||
import InputTextfield from "@root/components/InputTextfield"
|
import InputTextfield from "@root/components/InputTextfield"
|
||||||
import { sendPayment } from "@root/api/wallet"
|
import { sendPayment } from "@root/api/wallet"
|
||||||
import { getMessageFromFetchError } from "@frontend/kitui"
|
import { getMessageFromFetchError } from "@frontend/kitui"
|
||||||
import { enqueueSnackbar } from "notistack"
|
import { enqueueSnackbar } from "notistack"
|
||||||
import { currencyFormatter } from "@root/utils/currencyFormatter"
|
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"
|
import { useHistoryTracker } from "@root/utils/hooks/useHistoryTracker"
|
||||||
|
|
||||||
const paymentMethods = [
|
const paymentMethods = [
|
||||||
@ -44,6 +44,7 @@ export default function Payment() {
|
|||||||
useState<PaymentMethod | null>(null)
|
useState<PaymentMethod | null>(null)
|
||||||
const [paymentValueField, setPaymentValueField] = useState<string>("0")
|
const [paymentValueField, setPaymentValueField] = useState<string>("0")
|
||||||
const [paymentLink, setPaymentLink] = useState<string>("")
|
const [paymentLink, setPaymentLink] = useState<string>("")
|
||||||
|
const [fromSquiz, setIsFromSquiz] = useState<boolean>(false)
|
||||||
const location = useLocation()
|
const location = useLocation()
|
||||||
|
|
||||||
const notEnoughMoneyAmount =
|
const notEnoughMoneyAmount =
|
||||||
@ -51,9 +52,16 @@ export default function Payment() {
|
|||||||
|
|
||||||
const paymentValue = parseFloat(paymentValueField) * 100
|
const paymentValue = parseFloat(paymentValueField) * 100
|
||||||
|
|
||||||
useEffect(() => {
|
useLayoutEffect(() => {
|
||||||
setPaymentValueField((notEnoughMoneyAmount / 100).toString())
|
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// 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(() => {
|
useEffect(() => {
|
||||||
@ -62,7 +70,7 @@ export default function Payment() {
|
|||||||
|
|
||||||
async function handleChoosePaymentClick() {
|
async function handleChoosePaymentClick() {
|
||||||
if (Number(paymentValueField) !== 0) {
|
if (Number(paymentValueField) !== 0) {
|
||||||
const [sendPaymentResponse, sendPaymentError] = await sendPayment()
|
const [sendPaymentResponse, sendPaymentError] = await sendPayment({fromSquiz})
|
||||||
|
|
||||||
if (sendPaymentError) {
|
if (sendPaymentError) {
|
||||||
return enqueueSnackbar(sendPaymentError)
|
return enqueueSnackbar(sendPaymentError)
|
||||||
|
@ -132,6 +132,7 @@ function TariffPage() {
|
|||||||
return tariffElements;
|
return tariffElements;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
console.log(recentlyPurchased)
|
||||||
return (
|
return (
|
||||||
<SectionWrapper
|
<SectionWrapper
|
||||||
maxWidth="lg"
|
maxWidth="lg"
|
||||||
|
@ -9,15 +9,18 @@ export const useRecentlyPurchasedTariffs = () => {
|
|||||||
const tariffs = useTariffStore((state) => state.tariffs);
|
const tariffs = useTariffStore((state) => state.tariffs);
|
||||||
const historyData = useHistoryStore(state => state.history);
|
const historyData = useHistoryStore(state => state.history);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
console.log("юзэффект начинает работаььб")
|
||||||
async function fetchData() {
|
async function fetchData() {
|
||||||
try {
|
try {
|
||||||
const [response, errorMsg] = await getRecentlyPurchasedTariffs();
|
const [response, errorMsg] = await getRecentlyPurchasedTariffs();
|
||||||
|
console.log("responce" , response)
|
||||||
if (errorMsg) {
|
if (errorMsg) {
|
||||||
console.error("Произошла ошибка при вызове getRecentlyPurchasedTariffs:", errorMsg);
|
console.error("Произошла ошибка при вызове getRecentlyPurchasedTariffs:", errorMsg);
|
||||||
}
|
}
|
||||||
if (response) {
|
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)=>{
|
setRecentlyPurchased(tariffs.filter((tariffs)=>{
|
||||||
return recentlyTariffs.includes(tariffs._id)}));
|
return recentlyTariffs.includes(tariffs._id)}));
|
||||||
}
|
}
|
||||||
@ -27,6 +30,7 @@ export const useRecentlyPurchasedTariffs = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fetchData();
|
fetchData();
|
||||||
}, []);
|
}, [tariffs]);
|
||||||
|
console.log(recentlyPurchased)
|
||||||
return {recentlyPurchased}
|
return {recentlyPurchased}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user