diff --git a/src/pages/AccountPage/UserForm/UserForm.jsx b/src/pages/AccountPage/UserForm/UserForm.jsx index 8f0b942..450d963 100644 --- a/src/pages/AccountPage/UserForm/UserForm.jsx +++ b/src/pages/AccountPage/UserForm/UserForm.jsx @@ -28,6 +28,7 @@ import { format } from 'date-fns'; import defaultAvatar from 'images/sprite.svg'; import { useDispatch, useSelector } from 'react-redux'; import { + selectIsLoading, selectUserAvatarURL, selectUserBirthday, selectUserEmail, @@ -45,6 +46,7 @@ import { TELEGRAM_REGEX, } from '../../../constants/joiRegex'; import { toast } from 'react-toastify'; +import { Loader } from 'components/Loader/Loader'; export const UserForm = () => { const [image, setImage] = useState(null); @@ -60,301 +62,303 @@ export const UserForm = () => { const telegram = useSelector(selectUserTelegram); const avatar = useSelector(selectUserAvatarURL); const birthday = useSelector(selectUserBirthday) || Date.now(); + const isLoading = useSelector(selectIsLoading); const formattedDate = format(new Date(birthday), 'yyyy-MM-dd'); - const handleUpload = async event => { - event.preventDefault(); - if (!setImage) { - toast.error('Please select a file'); - return true; - } - }; + // const handleUpload = async event => { + // console.log('handleUpload '); + // event.preventDefault(); + // if (!setImage) { + // toast.error('Please select a file'); + // return true; + // } + // }; const FILE_SIZE = 2 * 1024 * 1024; const SUPPORTED_FORMATS = ['image/jpg', 'image/jpeg', 'image/png']; return ( - { - if (!value) { - return true; - } - const isGoodSize = value?.size <= FILE_SIZE; - if (!isGoodSize) { - toast.error('File too large'); - } - return isGoodSize; - }) - .test('format', 'Unsupported Format', value => { - if (!value) { - return true; - } - const isSupportedFormat = SUPPORTED_FORMATS.includes(value.type); - if (!isSupportedFormat) { - toast.error('Unsupported format'); - } - return isSupportedFormat; - }), - })} - onSubmit={async (values, { setSubmitting }) => { - await dispatch(userForm(values)).unwrap(); - setSubmitting(false); - toast.success('Form submitted successfully'); - }} - > - {formik => ( -
- - - {image ? ( - - ) : ( - <> - {avatar ? ( - - ) : ( - - + {isLoading && } + { + if (!value) { + return true; + } + const isGoodSize = value?.size <= FILE_SIZE; + if (!isGoodSize) { + toast.error('File too large'); + } + return isGoodSize; + }) + .test('format', 'Unsupported Format', value => { + if (!value) { + return true; + } + const isSupportedFormat = SUPPORTED_FORMATS.includes(value.type); + if (!isSupportedFormat) { + toast.error('Unsupported format'); + } + return isSupportedFormat; + }), + })} + onSubmit={async (values, { setSubmitting }) => { + await dispatch(userForm(values)).unwrap(); + setSubmitting(false); + + toast.success('Form submitted successfully'); + }} + > + {formik => ( + + + + {image ? ( + + ) : ( + <> + {avatar ? ( + - - )} - - )} - { - const file = event.target.files[0]; - formik.setFieldValue('avatar', file); - setImage(URL.createObjectURL(file)); - }} - accept={SUPPORTED_FORMATS.join(', ')} - /> - - - - - - + ) : ( + + + + )} + + )} + { + const file = event.target.files[0]; + formik.setFieldValue('avatar', file); + setImage(URL.createObjectURL(file)); + }} + accept={SUPPORTED_FORMATS.join(', ')} + /> + + + + + + - {name} - User - + {name} + User + - - - - - - { - formik.setFieldValue('birthday', date); - setBirthdayValidationCompleted(true); - }} - onBlur={formik.handleBlur} - dateFormat="dd-MM-yyyy" - maxDate={new Date()} - placeholderText="dd-MM-yyyy" - formatWeekDay={day => day.charAt(0)} - calendarStartDay={1} - hasError={formik.touched.birthday && formik.errors.birthday} - success={formik.touched.birthday || birthdayValidationCompleted} - /> - - {formik.touched.birthday && - formik.errors.birthday && - formik.errors.birthday} - - {/* {formik.touched.birthday && !formik.errors.birthday && ( + /> + + {formik.touched.birthday && formik.errors.birthday} + + {/* {formik.touched.birthday && !formik.errors.birthday && ( Valid birthday )} */} - + - - -
- )} -
+ + + + + )} + + ); };