diff --git a/src/App.js b/src/App.js index b1d3b31..87ae771 100644 --- a/src/App.js +++ b/src/App.js @@ -42,9 +42,11 @@ const App = () => { const [locale, setLocale] = useState( localStorage.getItem('userLanguage') ? localStorage.getItem('userLanguage') : 'TKM', ); + const [loaderActive, setLoaderActive] = useState(false); const providerValue = useMemo(() => ({ user, setUser }), [user, setUser]); const languageValue = useMemo(() => ({ locale, setLocale }), [locale, setLocale]); + useEffect(() => { const userLanguage = localStorage.getItem('userLanguage'); const userToken = localStorage.getItem('userToken'); diff --git a/src/components/ImmediateCreditsStages/AcceptStage.js b/src/components/ImmediateCreditsStages/AcceptStage.js index ba352e7..2e2fe02 100644 --- a/src/components/ImmediateCreditsStages/AcceptStage.js +++ b/src/components/ImmediateCreditsStages/AcceptStage.js @@ -1,6 +1,7 @@ // IMPORT MODULES import React, { useState, useContext } from 'react'; import { LanguageContext } from '../../backend/LanguageContext'; +import { UserContext } from '../../backend/UserContext'; import { useForm } from 'react-hook-form'; import { z } from 'zod'; import { zodResolver } from '@hookform/resolvers/zod'; @@ -18,15 +19,21 @@ const AcceptStage = ({ setStage, recepientAmount, creditDuration, - phoneNumber, - setPhoneNumber, + cardDetails, + setCardDetails, + borrowerData, + guaranterData, + isGuranter, }) => { const { locale } = useContext(LanguageContext); - const handlePhoneNumber = (e) => { - setPhoneNumber(e.target.value); + const handleCardDetails = (e) => { + setCardDetails(e.target.value); }; + const [isLoading, setIsLoading] = useState(false); + const [error, setError] = useState(false); + const { register, handleSubmit, @@ -39,10 +46,145 @@ const AcceptStage = ({ }, }); + console.log(borrowerData); + + const fetchData = async () => { + try { + setIsLoading(true); + // const response = await fetch( + // `http://shahsyotag.halkbank.gov.tm/onlineloancre-services/api/loancre`, + // { + // method: 'POST', + // headers: { + // 'Content-Type': 'application/json', + // }, + // body: JSON.stringify({ + // clientRecipient: { + // idSeria: 'I-AŞ', + // idNo: '478992', + // accountNo: '23908934160170143144000', + // name: 'BATYROVA', + // surname: 'Sulgun', + // availableAmount: 40900, + // clientType: 'recipient', + // signRecipient: { + // key1: '6SQbdKd6qWdP8Wa11rF2CVLfo+0H6a0RUZOfyTFBeiWmoQAIC2+zip5SD0xBAlKqE4rRUt+WDBBOasVG3EEC3ANA+yXkrVUXT4OPJBxDGg==', + // key2: 'AAECAwQFBgcICQoLDA0ODw==', + // }, + // }, + // clientGuarantor: { + // idSeria: 'I-AH', + // idNo: '435937', + // accountNo: '23908934160170851604201', + // name: 'Kirtow', + // surname: 'Mämmetniýaz', + // availableAmount: 40900, + // clientType: 'guarantor', + // signGuarantor: { + // key1: '6SQbdKd6qWdP8Wa11rF2CVLfLkcA66wbX5OewzhJey+hpAcOCmm0gppXCk1BBFKraKHicumzDoWrVN1Pz1oFYuv6t01fz2E9C1oLE6a2Ta0RsRo=', + // key2: 'AAECAwQFBgcICQoLDA0ODw==', + // }, + // }, + // availableAmount: 40900, + // creditCardAccountNumber: '23908934160170770960000', + // mrtIsInsuarance: 0, + // termInYears: 1, + // }), + // }, + // ); + const response = await fetch( + `http://shahsyotag.halkbank.gov.tm/onlineloancre-services/api/loancre`, + { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + clientRecipient: { + idSeria: borrowerData.idSeria, + idNo: borrowerData.idNo, + accountNo: borrowerData.accountNo, + name: borrowerData.name, + surname: borrowerData.surname, + availableAmount: borrowerData.availableAmount, + clientType: 'recipient', + signRecipient: borrowerData.signRecipient, + }, + clientGuarantor: isGuranter + ? { + idSeria: guaranterData.idSeria, + idNo: guaranterData.idNo, + accountNo: guaranterData.accountNo, + name: guaranterData.name, + surname: guaranterData.surname, + availableAmount: guaranterData.availableAmount, + clientType: 'guarantor', + signRecipient: guaranterData.signRecipient, + } + : null, + availableAmount: recepientAmount, + creditCardAccountNumber: cardDetails, + mrtIsInsuarance: isGuranter ? 1 : 0, + termInYears: creditDuration, + }), + }, + ); + + if (!response.ok) { + throw new Error(`HTTP error! Status: ${response.status}`); + } + + const responseJson = await response.json(); + + console.log(responseJson); + + setIsLoading(false); + } catch (error) { + console.error(error.toString()); + // Handle errors as needed + setError(true); + } + }; + const onSubmit = (data) => { + fetchData(); // console.log(data); }; + if (error) { + return ( +
+

Error...

+
+ +
+
+ ); + } + + if (isLoading) { + return ( +
+

Loading...

+
+ ); + } + return (
@@ -83,26 +225,24 @@ const AcceptStage = ({ {errors.duration && {errors.duration.message}}
-
@@ -123,10 +263,10 @@ const AcceptStage = ({
+
+ ); + } + return (
@@ -77,10 +174,10 @@ const PhoneAccept = ({ setStage }) => {