Skip to content

Commit 8fed8a4

Browse files
committed
add skeleton verification
1 parent 6f9383e commit 8fed8a4

3 files changed

Lines changed: 98 additions & 36 deletions

File tree

src/pages/Verification/Tabs/bank-tab/BankCardsUpload.jsx

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { useState } from "react";
77
import { getShebaInfo } from "@persian-tools/persian-tools";
88
import { getFieldTranslationByNames } from "../../../../services/Utility";
99
import useRequest from "../../../../services/Hooks/useRequest";
10+
import { Skeleton } from "../../../../components/Skeleton";
1011

1112
const Container = styled.div`
1213
display: flex;
@@ -135,29 +136,68 @@ const IconWrapper = styled.div`
135136
}
136137
`;
137138

139+
// اسکلتون برای کارت بانکی
140+
const SkeletonCard = styled.div`
141+
width: 250px;
142+
height: 190px;
143+
border-radius: 10px;
144+
background-color: ${(props) =>
145+
props.theme.colors.newColors.otherColors.inputBg};
146+
147+
@media (min-width: 840px) {
148+
width: 305px;
149+
height: 190px;
150+
}
151+
@media (min-width: 940px) {
152+
width: 380px;
153+
height: 190px;
154+
}
155+
`;
156+
138157
const BankCardsUpload = ({
139158
cards,
140159
setCards,
141160
openAddModal,
142161
setOpenAddModal,
143162
openDeleteModal,
144163
setOpenDeleteModal,
164+
isLoading,
145165
}) => {
146166
const [deleteIndex, setDeleteIndex] = useState(null);
147167
const { Request, HTTP_METHOD } = useRequest();
148-
const handleDeleteCard = ({ index, id }) => {
149168

169+
const handleDeleteCard = ({ index, id }) => {
150170
Request(`bank-accounts/${id}`, HTTP_METHOD.DELETE).then((response) => {
151171
setDeleteIndex(index);
152172
setOpenDeleteModal(true);
153173
});
154174
};
155175

176+
// اسکلتون لودینگ
177+
if (isLoading) {
178+
return (
179+
<Container>
180+
<BankCard>
181+
{Array.from({ length: 1 }).map((_, index) => (
182+
<SkeletonCard key={index}>
183+
<Skeleton width="100%" height="190px" radius="10px" />
184+
</SkeletonCard>
185+
))}
186+
<UploadWrapper>
187+
<Upload>
188+
+<span> {getFieldTranslationByNames("890")}</span>
189+
</Upload>
190+
</UploadWrapper>
191+
</BankCard>
192+
</Container>
193+
);
194+
}
195+
156196
return (
157197
<>
158198
<Container>
159199
<BankCard>
160-
{cards.map((card, i) => {
200+
{cards?.map((card, i) => {
161201
return (
162202
<UploadWrapper key={i}>
163203
<Image>
@@ -207,4 +247,4 @@ const BankCardsUpload = ({
207247
);
208248
};
209249

210-
export default BankCardsUpload;
250+
export default BankCardsUpload;

src/pages/Verification/Tabs/bank-tab/BankTab.jsx

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import BankCardsUpload from "./BankCardsUpload";
2-
32
import styled from "styled-components";
43
import { useEffect, useState } from "react";
54
import Title from "../../../../components/Title";
@@ -14,20 +13,33 @@ const Wrapper = styled.div`
1413
flex-direction: column;
1514
gap: 30px;
1615
`;
16+
1717
const BankTab = () => {
1818
const [isError, setIsError] = useState(false);
1919
const [errors, setErrors] = useState([]);
2020
const [cards, setCards] = useState([]);
2121
const [openAddModal, setOpenAddModal] = useState(false);
2222
const [openDeleteModal, setOpenDeleteModal] = useState(false);
23-
const { openErrorModal, setOpenErrorModal } = useState();
23+
const [openErrorModal, setOpenErrorModal] = useState(false);
24+
const [loading, setLoading] = useState(true); // اضافه شد
2425

2526
const { Request } = useRequest();
27+
2628
useEffect(() => {
27-
Request("bank-accounts").then((response) => {
28-
setCards(response.data.data);
29-
});
29+
setLoading(true);
30+
Request("bank-accounts")
31+
.then((response) => {
32+
setCards(response.data.data || []);
33+
})
34+
.catch((error) => {
35+
console.error("Error fetching bank accounts:", error);
36+
setCards([]);
37+
})
38+
.finally(() => {
39+
setLoading(false);
40+
});
3041
}, []);
42+
3143
return (
3244
<Container>
3345
<Wrapper>
@@ -49,6 +61,7 @@ const BankTab = () => {
4961
cards={cards}
5062
setCards={setCards}
5163
setIsError={setIsError}
64+
isLoading={loading}
5265
/>
5366
</Wrapper>
5467
{openErrorModal && (
@@ -58,4 +71,4 @@ const BankTab = () => {
5871
);
5972
};
6073

61-
export default BankTab;
74+
export default BankTab;

src/pages/Verification/Tabs/identity-tab/IdentityInputs.jsx

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
} from "../../../../services/Utility";
1616
import * as Sentry from "@sentry/react";
1717
import Container from "../../../../components/Common/Container";
18+
1819
const BankContainer = styled.div`
1920
margin: 20px 0;
2021
display: flex;
@@ -24,6 +25,7 @@ const BankContainer = styled.div`
2425
grid-template-columns: 2fr 3fr;
2526
}
2627
`;
28+
2729
const IdentityInputs = ({
2830
data,
2931
kyc,
@@ -43,12 +45,14 @@ const IdentityInputs = ({
4345
const [uploadResponse, setUploadResponse] = useState(null);
4446
const [isVideoUploaded, setIsVideoUploaded] = useState(false);
4547
const [textVerify, setTextVerify] = useState("");
48+
const [isSending, setIsSending] = useState(false); // حالت لودینگ دکمه
4649
const { Request, HTTP_METHOD } = useRequest();
50+
4751
const sendHandler = () => {
4852
let errorMessages = [];
49-
let newDetails = [...data]; // کپی از دیتیلز برای به‌روزرسانی ارور‌ها
53+
let newDetails = [...data];
5054

51-
// Validation checks and storing error messages and fields
55+
// Validation checks
5256
if (!inputValues.fname) {
5357
errorMessages.push("نام وارد نشده است.");
5458
newDetails[0].error = true;
@@ -121,7 +125,18 @@ const IdentityInputs = ({
121125
}
122126

123127
setErrors(errorMessages);
124-
setDetails(newDetails); // به‌روزرسانی دیتیلز با ارور‌ها
128+
setDetails(newDetails);
129+
130+
if (errorMessages.length > 0) {
131+
setIdentityError(true);
132+
Sentry.captureMessage("Identity verification form validation failed", {
133+
level: "warning",
134+
extra: { errors: errorMessages },
135+
});
136+
return;
137+
}
138+
139+
setIsSending(true); // شروع لودینگ
125140

126141
const requestData = new FormData();
127142
requestData.append("fname", inputValues.fname);
@@ -142,32 +157,26 @@ const IdentityInputs = ({
142157
);
143158
requestData.append("_method", "put");
144159

145-
if (errorMessages.length === 0) {
146-
setIdentityError(false);
147-
Request(`kyc`, HTTP_METHOD.POST, requestData, {
148-
"Content-Type": "multipart/form-data",
160+
Request(`kyc`, HTTP_METHOD.POST, requestData, {
161+
"Content-Type": "multipart/form-data",
162+
})
163+
.then((res) => {
164+
setSubmitted(true);
149165
})
150-
.then((res) => {
151-
setSubmitted(true);
152-
})
153-
.catch((error) => {
154-
Sentry.captureException(error, {
155-
tags: {
156-
section: "identity-verification",
157-
},
158-
});
159-
ToastError(error.response.data.message);
166+
.catch((error) => {
167+
Sentry.captureException(error, {
168+
tags: { section: "identity-verification" },
160169
});
161-
} else {
162-
setIdentityError(true);
163-
Sentry.captureMessage("Identity verification form validation failed", {
164-
level: "warning",
165-
extra: {
166-
errors: errorMessages,
167-
},
170+
ToastError(error.response?.data?.message || "خطا در ارسال اطلاعات");
171+
})
172+
.finally(() => {
173+
setIsSending(false); // پایان لودینگ
168174
});
169-
}
170175
};
176+
177+
// بررسی غیرفعال بودن دکمه
178+
const isDisabled = !isVideoUploaded;
179+
171180
return (
172181
<Container identityError={identityError}>
173182
<BankContainer>
@@ -202,7 +211,7 @@ const IdentityInputs = ({
202211
large
203212
label={getFieldTranslationByNames("877")}
204213
onclick={sendHandler}
205-
disabled={isVideoUploaded ? false : true/*"pending" for loading ui*/ }
214+
disabled={isDisabled ? true : isSending ? "pending" : false}
206215
/>
207216
</BankContainer>
208217
{openErrorModal && (
@@ -212,4 +221,4 @@ const IdentityInputs = ({
212221
);
213222
};
214223

215-
export default IdentityInputs;
224+
export default IdentityInputs;

0 commit comments

Comments
 (0)