form page loader

This commit is contained in:
kurpfish 2021-08-25 13:27:54 +03:00
parent 11616b8a38
commit 3a01fce386
2 changed files with 9 additions and 7 deletions

View File

@ -3,6 +3,7 @@ import style from './Form.module.css';
import { fetchForm } from '../../server/server'; import { fetchForm } from '../../server/server';
import { auth } from '../../redux/outstaffingSlice'; import { auth } from '../../redux/outstaffingSlice';
import { useHistory, useParams, Redirect } from 'react-router-dom'; import { useHistory, useParams, Redirect } from 'react-router-dom';
import { Loader } from '../Loader/Loader';
import PhoneInput from 'react-phone-input-2' import PhoneInput from 'react-phone-input-2'
import 'react-phone-input-2/lib/style.css' import 'react-phone-input-2/lib/style.css'
import './form.css'; import './form.css';
@ -25,6 +26,7 @@ const Form = () => {
phone: '', phone: '',
comment: '', comment: '',
}); });
const [isFetching, setIsFetching] = useState(false);
const handleChange = (e) => { const handleChange = (e) => {
const { id, value } = e.target; const { id, value } = e.target;
@ -38,6 +40,7 @@ const Form = () => {
const handleSubmit = (e) => { const handleSubmit = (e) => {
e.preventDefault(); e.preventDefault();
setIsFetching(true)
const formData = new FormData(); const formData = new FormData();
formData.append('profile_id', urlParams.id); formData.append('profile_id', urlParams.id);
formData.append('email', data.email); formData.append('email', data.email);
@ -48,14 +51,13 @@ const Form = () => {
profile_id: urlParams.id, profile_id: urlParams.id,
...data, ...data,
}, history, role, logout: dispatch(auth(false)) }).then( (res)=> res.json() }, history, role, logout: dispatch(auth(false)) }).then( (res)=> res.json()
.then( resJSON => setStatus(resJSON)) .then( resJSON => {
setStatus(resJSON);
setIsFetching(false);
})
) )
}; };
console.log('s',status)
return ( return (
<> <>
{status && <SweetAlert {status && <SweetAlert
@ -104,7 +106,7 @@ const Form = () => {
></textarea> ></textarea>
<button onClick={handleSubmit} className={style.form__btn} type="submit"> <button onClick={handleSubmit} className={style.form__btn} type="submit">
Отправить { isFetching ? <Loader /> : 'Отправить' }
</button> </button>
</form> </form>
</div> </div>

View File

@ -1,4 +1,4 @@
import React from 'react'; import React, { useState } from 'react';
import { useDispatch, useSelector } from 'react-redux'; import { useDispatch, useSelector } from 'react-redux';
import { useHistory, useParams, Link } from 'react-router-dom'; import { useHistory, useParams, Link } from 'react-router-dom';
import { currentCandidate, selectCurrentCandidate, auth } from '../redux/outstaffingSlice'; import { currentCandidate, selectCurrentCandidate, auth } from '../redux/outstaffingSlice';