api complete
This commit is contained in:
parent
6804323434
commit
44e5b08a31
|
|
@ -17,6 +17,9 @@ export const changePassword = (
|
|||
setState(res.data.user);
|
||||
setIsLoading(false);
|
||||
setSuccess(true);
|
||||
setTimeout(() => {
|
||||
setSuccess(false);
|
||||
}, 2000);
|
||||
if (tokenSaved) {
|
||||
localStorage.setItem("userToken", res.data.token);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,11 +4,9 @@ import axios from "axios";
|
|||
export const getUserInfo = (url, userToken, setState, setLoaderActive) => {
|
||||
axios
|
||||
.get(`${url}?token=${userToken}`)
|
||||
.then((res, err) => {
|
||||
.then((res) => {
|
||||
setLoaderActive(false);
|
||||
if (err) {
|
||||
return `Failed to fetch user info: ${err}`;
|
||||
}
|
||||
|
||||
if (setState) {
|
||||
setState(res.data.me);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
// IMPORT MODULES
|
||||
import axios from "axios";
|
||||
|
||||
export const sendMessage = (url, token, data, stateSetter) => {
|
||||
export const sendMessage = (url, token, data, stateSetter, loader) => {
|
||||
axios
|
||||
.post(`${url}?token=${token}`, data)
|
||||
.then((res) => {
|
||||
stateSetter(false);
|
||||
loader();
|
||||
})
|
||||
.catch(() => {
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,6 +2,12 @@ import axios from "axios";
|
|||
|
||||
export const sendRequest = (url, token, data, setState, setLoader) => {
|
||||
const form = new FormData();
|
||||
|
||||
let today = new Date();
|
||||
let dd = String(today.getDate()).padStart(2, "0");
|
||||
let mm = String(today.getMonth() + 1).padStart(2, "0"); //January is 0!
|
||||
let yyyy = today.getFullYear();
|
||||
|
||||
data.file.map((el) => {
|
||||
form.append("file[]", el);
|
||||
});
|
||||
|
|
@ -22,6 +28,7 @@ export const sendRequest = (url, token, data, setState, setLoader) => {
|
|||
form.append("amount_of_salary", data.salary);
|
||||
form.append("position", data.position);
|
||||
form.append("work_experience", data.exp);
|
||||
form.append("date", `${dd}.${mm}.${yyyy}`);
|
||||
axios
|
||||
.post(`${url}?token=${token}`, form)
|
||||
.then((res) => {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,10 @@ import axios from "axios";
|
|||
// import { getDate } from "../helpers/Date";
|
||||
|
||||
export const sendRequestCard = (url, token, data, setLoader) => {
|
||||
let today = new Date().toLocaleDateString();
|
||||
let today = new Date();
|
||||
let dd = String(today.getDate()).padStart(2, "0");
|
||||
let mm = String(today.getMonth() + 1).padStart(2, "0"); //January is 0!
|
||||
let yyyy = today.getFullYear();
|
||||
const form = new FormData();
|
||||
data.file.map((el) => {
|
||||
form.append("file[]", el);
|
||||
|
|
@ -24,13 +27,15 @@ export const sendRequestCard = (url, token, data, setLoader) => {
|
|||
form.append("selected_time", data.selected_time);
|
||||
form.append("the_codeword", data.the_codeword);
|
||||
form.append("sms_notification", data.sms_notification);
|
||||
// form.append("date", `today`);
|
||||
form.append("date", `${dd}.${mm}.${yyyy}`);
|
||||
|
||||
axios
|
||||
.post(`${url}?token=${token}`, form)
|
||||
.then((res) => {
|
||||
window.open(res.request.responseURL, "_blank").focus();
|
||||
setLoader(false);
|
||||
if (setLoader) {
|
||||
setLoader(false);
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
setLoader(false);
|
||||
|
|
|
|||
|
|
@ -10,7 +10,13 @@ import next_reverse from "../../icons/next-reverse.svg";
|
|||
import { sendRequestCard } from "../../backend/sendRequestCard";
|
||||
import { getUserInfo } from "../../backend/getUserInfo";
|
||||
|
||||
const CardStage6 = ({ setStage, data, setLoader, setModalOpen }) => {
|
||||
const CardStage6 = ({
|
||||
setStage,
|
||||
data,
|
||||
setLoader,
|
||||
setModalOpen,
|
||||
setSuccess,
|
||||
}) => {
|
||||
const { setUser } = useContext(UserContext);
|
||||
const token = localStorage.getItem("userToken");
|
||||
const postUrl = "http://95.85.124.85:8000/api/online_card";
|
||||
|
|
@ -118,8 +124,14 @@ const CardStage6 = ({ setStage, data, setLoader, setModalOpen }) => {
|
|||
onClick={() => {
|
||||
setLoader(true);
|
||||
setModalOpen(false);
|
||||
sendRequestCard(postUrl, token, data, setLoader);
|
||||
getUserInfo(getUrl, token, setUser, () => null);
|
||||
sendRequestCard(postUrl, token, data, () => {
|
||||
setSuccess(true);
|
||||
setLoader(false);
|
||||
setTimeout(() => {
|
||||
setSuccess(false);
|
||||
getUserInfo(getUrl, token, setUser, () => null);
|
||||
}, 2000);
|
||||
});
|
||||
}}
|
||||
>
|
||||
<div>
|
||||
|
|
|
|||
|
|
@ -121,17 +121,15 @@ const CreditStage6 = ({
|
|||
postUrl,
|
||||
token,
|
||||
data,
|
||||
(res) => {
|
||||
if (res.headers.status === "200") {
|
||||
setSuccess(true);
|
||||
setTimeout(() => {
|
||||
setSuccess(false);
|
||||
}, 2000);
|
||||
}
|
||||
() => {
|
||||
setSuccess(true);
|
||||
setTimeout(() => {
|
||||
setSuccess(false);
|
||||
getUserInfo(getUrl, token, setUser, () => null);
|
||||
}, 2000);
|
||||
},
|
||||
setLoader
|
||||
);
|
||||
getUserInfo(getUrl, token, setUser, () => null);
|
||||
}}
|
||||
>
|
||||
<div>
|
||||
|
|
|
|||
|
|
@ -21,7 +21,14 @@ import CardStage3 from "../CardStages/CardStage3";
|
|||
import CardStage4 from "../CardStages/CardStage4";
|
||||
import CardStage6 from "../CardStages/CardStage6";
|
||||
|
||||
const ModalForm = ({ modalOpen, setModalOpen, stage, setStage, setLoader }) => {
|
||||
const ModalForm = ({
|
||||
modalOpen,
|
||||
setModalOpen,
|
||||
stage,
|
||||
setStage,
|
||||
setLoader,
|
||||
setSuccess,
|
||||
}) => {
|
||||
const window = useRef();
|
||||
const [data, setData] = useState({});
|
||||
|
||||
|
|
@ -148,6 +155,7 @@ const ModalForm = ({ modalOpen, setModalOpen, stage, setStage, setLoader }) => {
|
|||
setData={setData}
|
||||
setLoader={setLoader}
|
||||
setModalOpen={setModalOpen}
|
||||
setSuccess={setSuccess}
|
||||
/>
|
||||
) : (
|
||||
""
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// IMPORT MODULES
|
||||
import React, { useCallback, useContext, useState } from "react";
|
||||
import React, { useContext } from "react";
|
||||
import { UserContext } from "../backend/UserContext";
|
||||
|
||||
// IMPORT COMPONENTS
|
||||
|
|
@ -37,7 +37,62 @@ const Base = () => {
|
|||
<th>Статус</th>
|
||||
<th>Действие</th>
|
||||
</tr>
|
||||
|
||||
{user ? (
|
||||
user.online_credit.length !== 0 ? (
|
||||
user.online_credit.map((el, i) => {
|
||||
return (
|
||||
<tr key={i}>
|
||||
<td>#{el.id}</td>
|
||||
<td>{el.type}</td>
|
||||
<td>{el.date}</td>
|
||||
<td>--status</td>
|
||||
<td>--action</td>
|
||||
</tr>
|
||||
);
|
||||
})
|
||||
) : user ? (
|
||||
user.online_card.length !== 0 ? (
|
||||
""
|
||||
) : (
|
||||
<tr>
|
||||
<td>Заявок нет</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
)
|
||||
) : null
|
||||
) : user ? (
|
||||
user.online_card.length !== 0 ? (
|
||||
""
|
||||
) : (
|
||||
<tr>
|
||||
<td>Заявок нет</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
)
|
||||
) : null}
|
||||
{user
|
||||
? user.online_card.length !== 0
|
||||
? user.online_card.map((el, i) => {
|
||||
return (
|
||||
<tr key={i}>
|
||||
<td>#{el.id}</td>
|
||||
<td>{el.selected_card}</td>
|
||||
<td>{el.date}</td>
|
||||
<td>--status</td>
|
||||
<td>--action</td>
|
||||
</tr>
|
||||
);
|
||||
})
|
||||
: null
|
||||
: null}
|
||||
{/* {user
|
||||
? user.online_credit.length !== 0
|
||||
? user.online_credit.map((el, i) => {
|
||||
return (
|
||||
|
|
@ -65,16 +120,8 @@ const Base = () => {
|
|||
</tr>
|
||||
);
|
||||
})
|
||||
) : (
|
||||
<tr>
|
||||
<td>Заявок нет</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
)
|
||||
) : (
|
||||
) : user.online_credit.length !== 0 ? null
|
||||
: (
|
||||
<tr>
|
||||
<td>Заявок нет</td>
|
||||
<td></td>
|
||||
|
|
@ -82,7 +129,7 @@ const Base = () => {
|
|||
<td></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
)}
|
||||
)} */}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -6,12 +6,14 @@ import { UserContext } from "../backend/UserContext";
|
|||
import Breadcrumb from "../components/global/Breadcrumb";
|
||||
import ModalForm from "../components/cards/ModalForm";
|
||||
import Loader from "../components/global/Loader";
|
||||
import Success from "../components/global/Success";
|
||||
|
||||
// IMPORT IMAGES
|
||||
import card from "../icons/card-black.svg";
|
||||
import add from "../icons/add.svg";
|
||||
|
||||
const Cards = () => {
|
||||
const [success, setSuccess] = useState(false);
|
||||
const { user } = useContext(UserContext);
|
||||
const [loader, setLoader] = useState(false);
|
||||
const [modalOpen, setModalOpen] = useState(false);
|
||||
|
|
@ -25,6 +27,7 @@ const Cards = () => {
|
|||
}, [modalOpen]);
|
||||
return (
|
||||
<section className="cards">
|
||||
{success ? <Success message={"Ваш запрос успешно отправлен!"} /> : null}
|
||||
<Breadcrumb
|
||||
image={card}
|
||||
link={"/home/cards"}
|
||||
|
|
@ -37,6 +40,7 @@ const Cards = () => {
|
|||
setStage={setStage}
|
||||
loader={loader}
|
||||
setLoader={setLoader}
|
||||
setSuccess={setSuccess}
|
||||
/>
|
||||
{loader ? <Loader /> : null}
|
||||
<div className="container">
|
||||
|
|
@ -70,13 +74,15 @@ const Cards = () => {
|
|||
{user ? (
|
||||
user.online_card.length !== 0 ? (
|
||||
user.online_card.map((el, i) => {
|
||||
<tr key={i}>
|
||||
<td>#{el.id}</td>
|
||||
<td>{el.selected_card}</td>
|
||||
<td>{el.date}</td>
|
||||
<td>--status</td>
|
||||
<td>--action</td>
|
||||
</tr>;
|
||||
return (
|
||||
<tr key={i}>
|
||||
<td>#{el.id}</td>
|
||||
<td>{el.selected_card}</td>
|
||||
<td>{el.date}</td>
|
||||
<td>--status</td>
|
||||
<td>--action</td>
|
||||
</tr>
|
||||
);
|
||||
})
|
||||
) : (
|
||||
<tr>
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import React, { useState, useEffect } from "react";
|
|||
import CustomSelect from "../components/global/CustomSelect";
|
||||
import Breadcrumb from "../components/global/Breadcrumb";
|
||||
import Loader from "../components/global/Loader";
|
||||
import Success from "../components/global/Success";
|
||||
|
||||
// IMPORT FUNCTIONS
|
||||
import { sendMessage } from "../backend/sendMessage";
|
||||
|
|
@ -14,6 +15,7 @@ import mail from "../icons/mail-black.svg";
|
|||
import send from "../icons/send.svg";
|
||||
|
||||
const ContactUs = () => {
|
||||
const [success, setSuccess] = useState(false);
|
||||
const token = localStorage.getItem("userToken");
|
||||
const postUrl = "http://95.85.124.85:8000/api/message";
|
||||
const formData = new FormData();
|
||||
|
|
@ -33,6 +35,9 @@ const ContactUs = () => {
|
|||
}, [topic, inputValid]);
|
||||
return (
|
||||
<section className="contact-us">
|
||||
{success ? (
|
||||
<Success message={"Ваше сообщение успешно отправлено!"} />
|
||||
) : null}
|
||||
<Breadcrumb
|
||||
image={mail}
|
||||
link={"/home/contact-us"}
|
||||
|
|
@ -90,12 +95,23 @@ const ContactUs = () => {
|
|||
disabled={!btnEnabled}
|
||||
className="sign-btn cu-btn"
|
||||
onClick={() => {
|
||||
setIsLoading(true);
|
||||
formData.append("subject", topic);
|
||||
formData.append("message", inputValid.message);
|
||||
sendMessage(postUrl, token, formData, (e) => {
|
||||
setIsLoading(e);
|
||||
});
|
||||
setIsLoading(true);
|
||||
sendMessage(
|
||||
postUrl,
|
||||
token,
|
||||
formData,
|
||||
(e) => {
|
||||
setIsLoading(e);
|
||||
},
|
||||
() => {
|
||||
setSuccess(true);
|
||||
setTimeout(() => {
|
||||
setSuccess(false);
|
||||
}, 2000);
|
||||
}
|
||||
);
|
||||
}}
|
||||
>
|
||||
<div>
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ const Credits = () => {
|
|||
|
||||
return (
|
||||
<section className="cards">
|
||||
{success ? <Success message={"ASDASDASD"} /> : null}
|
||||
{success ? <Success message={"Ваш запрос успешно отправлен!"} /> : null}
|
||||
<Breadcrumb image={credit} link={"/home/credits"} linkTitle={"Кредиты"} />
|
||||
<CreditModal
|
||||
setModalOpen={setModalOpen}
|
||||
|
|
@ -71,13 +71,15 @@ const Credits = () => {
|
|||
{user ? (
|
||||
user.online_credit.length !== 0 ? (
|
||||
user.online_credit.map((el, i) => {
|
||||
<tr key={i}>
|
||||
<td>#{el.id}</td>
|
||||
<td>{el.type}</td>
|
||||
<td>{el.date}</td>
|
||||
<td>--status</td>
|
||||
<td>--action</td>
|
||||
</tr>;
|
||||
return (
|
||||
<tr key={i}>
|
||||
<td>#{el.id}</td>
|
||||
<td>{el.type}</td>
|
||||
<td>{el.date}</td>
|
||||
<td>--status</td>
|
||||
<td>--action</td>
|
||||
</tr>
|
||||
);
|
||||
})
|
||||
) : (
|
||||
<tr>
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
// IMPORT MODULES
|
||||
import React, { useState, useEffect, useContext } from "react";
|
||||
import React, { useState, useEffect, useContext, useRef } from "react";
|
||||
import { UserContext } from "../backend/UserContext";
|
||||
|
||||
// IMPORT COMPONENTS
|
||||
import Breadcrumb from "../components/global/Breadcrumb";
|
||||
import Loader from "../components/global/Loader";
|
||||
import Success from "../components/global/Success";
|
||||
|
||||
// IMPORT IMAGES
|
||||
import recovery from "../icons/recovery.svg";
|
||||
|
|
@ -17,6 +18,9 @@ import { ValidateEmail } from "../validators/ValidateEmail";
|
|||
import { changePassword } from "../backend/changePassword";
|
||||
|
||||
const Recovery = () => {
|
||||
const inp1 = useRef();
|
||||
const inp2 = useRef();
|
||||
const inp3 = useRef();
|
||||
const [success, setSuccess] = useState(false);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const postUrl = "http://95.85.124.85:8000/api/me";
|
||||
|
|
@ -46,6 +50,7 @@ const Recovery = () => {
|
|||
|
||||
return (
|
||||
<section className="p-recovery">
|
||||
{success ? <Success message={"Ваш пароль успешно изменен!"} /> : null}
|
||||
<Breadcrumb
|
||||
image={recovery}
|
||||
link={"/home/recovery"}
|
||||
|
|
@ -68,6 +73,9 @@ const Recovery = () => {
|
|||
disabled={!btnEnabled}
|
||||
className="sign-btn cu-btn"
|
||||
onClick={() => {
|
||||
inp1.current.value = "";
|
||||
inp2.current.value = "";
|
||||
inp3.current.value = "";
|
||||
setIsLoading(true);
|
||||
formData.append("email", inputValid.email);
|
||||
formData.append("password", inputValid.new);
|
||||
|
|
@ -99,24 +107,42 @@ const Recovery = () => {
|
|||
<div className="input-block">
|
||||
<label htmlFor="email">E-mail</label>
|
||||
<input
|
||||
ref={inp3}
|
||||
type="text"
|
||||
id="email"
|
||||
autoComplete="true"
|
||||
onChange={(e) => {
|
||||
if (ValidateEmail(e.target.value)) {
|
||||
setInputValid({
|
||||
...inputValid,
|
||||
email: e.target.value,
|
||||
});
|
||||
setValidate(true);
|
||||
if (ValidateEmail(e.target.value) && user) {
|
||||
if (user.email === e.target.value) {
|
||||
setInputValid({
|
||||
...inputValid,
|
||||
email: e.target.value,
|
||||
});
|
||||
} else {
|
||||
setInputValid({ ...inputValid, email: false });
|
||||
}
|
||||
} else {
|
||||
setInputValid({ ...inputValid, email: false });
|
||||
}
|
||||
}}
|
||||
/>
|
||||
{validate ? (
|
||||
<span
|
||||
className={
|
||||
inputValid.email ? "pass-check" : "pass-check active"
|
||||
}
|
||||
>
|
||||
Введен неверный E-mail
|
||||
</span>
|
||||
) : (
|
||||
""
|
||||
)}
|
||||
</div>
|
||||
<div className="input-block rel-block">
|
||||
<label htmlFor="new-p">Новый пароль</label>
|
||||
<input
|
||||
ref={inp1}
|
||||
autoComplete="false"
|
||||
type={isPassword ? "password" : "text"}
|
||||
id="new-p"
|
||||
|
|
@ -154,6 +180,7 @@ const Recovery = () => {
|
|||
<div className="input-block">
|
||||
<label htmlFor="confirm-p">Повторите новый пароль</label>
|
||||
<input
|
||||
ref={inp2}
|
||||
autoComplete="false"
|
||||
type={isPassword ? "password" : "text"}
|
||||
id="confirm-p"
|
||||
|
|
@ -177,11 +204,6 @@ const Recovery = () => {
|
|||
)}
|
||||
</div>
|
||||
</div>
|
||||
{success ? (
|
||||
<h1 className="success">Ваш пароль успешно изменен!</h1>
|
||||
) : (
|
||||
""
|
||||
)}
|
||||
</form>
|
||||
</div>
|
||||
) : (
|
||||
|
|
|
|||
|
|
@ -15,11 +15,12 @@
|
|||
h1 {
|
||||
font-size: 4rem;
|
||||
color: $base-green;
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
|
||||
.wrapper {
|
||||
width: 100px;
|
||||
width: 10rem;
|
||||
margin: 4em auto 0;
|
||||
}
|
||||
|
||||
|
|
@ -38,3 +39,31 @@
|
|||
stroke-dashoffset: 0;
|
||||
}
|
||||
}
|
||||
|
||||
// MEDIA
|
||||
|
||||
@media screen and (max-width: 900px) {
|
||||
.success {
|
||||
h1 {
|
||||
font-size: 3rem;
|
||||
padding: 0 2rem;
|
||||
}
|
||||
}
|
||||
.wrapper {
|
||||
width: 8rem;
|
||||
margin: 4em auto 0;
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (max-width: 500px) {
|
||||
.success {
|
||||
h1 {
|
||||
font-size: 2.6rem;
|
||||
padding: 0 2rem;
|
||||
}
|
||||
}
|
||||
.wrapper {
|
||||
width: 7rem;
|
||||
margin: 4em auto 0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,9 @@ export const ValidatePhoneNumber = (number) => {
|
|||
const numberRegEx3 = /^([+])?\d{11}$/;
|
||||
const numberRegEx4 = /^([+])?\d{12}$/;
|
||||
const numberRegEx5 = /^([+])?\d{9}$/;
|
||||
const numberRegEx6 = /^([+])?\d{6}$/;
|
||||
const numberRegEx7 = /^([+])?\d{5}$/;
|
||||
const numberRegEx8 = /^([+])?\d{4}$/;
|
||||
if (number.match(numberRegEx1)) {
|
||||
return true;
|
||||
}
|
||||
|
|
@ -19,5 +22,14 @@ export const ValidatePhoneNumber = (number) => {
|
|||
if (number.match(numberRegEx5)) {
|
||||
return true;
|
||||
}
|
||||
if (number.match(numberRegEx6)) {
|
||||
return true;
|
||||
}
|
||||
if (number.match(numberRegEx7)) {
|
||||
return true;
|
||||
}
|
||||
if (number.match(numberRegEx8)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue