diff --git a/src/apps/onboarding/src/components/modal-upload-photo/index.tsx b/src/apps/onboarding/src/components/modal-upload-photo/index.tsx index 067c21f79..d56f7a01d 100644 --- a/src/apps/onboarding/src/components/modal-upload-photo/index.tsx +++ b/src/apps/onboarding/src/components/modal-upload-photo/index.tsx @@ -1,5 +1,5 @@ import { Dispatch, FC, SetStateAction, useCallback, useEffect, useState } from 'react' -import { DropzoneState, useDropzone } from 'react-dropzone' +import { DropzoneState, FileRejection, useDropzone } from 'react-dropzone' import _ from 'lodash' import classNames from 'classnames' @@ -22,8 +22,23 @@ const ModalUploadPhoto: FC = (props: ModalUploadPhotoProp const [imgUrl, setImgUrl] = useState('') const [isSaving, setIsSaving]: [boolean, Dispatch>] = useState(false) + const [errorUploadFile, setErrorUploadFile] = useState('') + + const onDrop = useCallback((acceptedFiles: File[], fileRejections: FileRejection[]) => { + if (!acceptedFiles.length && fileRejections.length) { + const errorCode = _.get(fileRejections, '[0].errors[0].code') + let errorMessage = _.get(fileRejections, '[0].errors[0].message', '') + if (errorCode === 'file-invalid-type') { + errorMessage = 'Invalid file format' + } else if (errorCode === 'file-too-large') { + errorMessage = 'File is larger than 2MB' + } + + setErrorUploadFile(errorMessage) + } else { + setErrorUploadFile('') + } - const onDrop = useCallback((acceptedFiles: File[]) => { setMyFiles([...acceptedFiles]) }, []) @@ -64,6 +79,51 @@ const ModalUploadPhoto: FC = (props: ModalUploadPhotoProp } } + function getDragAndDropUI(): JSX.Element { + if (isSaving) { + return ( +
+ Uploading... +
+
+
+
+ ) + } + + if (errorUploadFile) { + return ( +
+ + {errorUploadFile} +
+ ) + } + + if (imgUrl) { + return ( +
+ + +
+ ) + } + + return ( +
+ + + Drag and drop your file here +
+ or +
+ + BROWSE + +
+ ) + } + return ( = (props: ModalUploadPhotoProp 'd-flex mobile-flex-column align-items-start mobile-gap-16', )} > - {(!isSaving && !imgUrl) ? ( -
- - - Drag and drop your file here -
- or -
- - BROWSE - -
- ) : undefined} - - {(!isSaving && imgUrl) ? ( -
- - -
- ) : undefined} - - {isSaving ? ( -
- Uploading... -
-
-
-
- ) : undefined} + {getDragAndDropUI()}
Add a photo that you would like to share to the customers and community members. diff --git a/src/apps/onboarding/src/pages/onboarding/index.tsx b/src/apps/onboarding/src/pages/onboarding/index.tsx index 61a27c64f..b9ca5cc86 100644 --- a/src/apps/onboarding/src/pages/onboarding/index.tsx +++ b/src/apps/onboarding/src/pages/onboarding/index.tsx @@ -1,6 +1,6 @@ import { FC, useContext, useEffect } from 'react' -import { Outlet, Routes } from 'react-router-dom' -import { connect, Provider } from 'react-redux' +import { Outlet, Routes, useLocation } from 'react-router-dom' +import { Provider, useDispatch, useSelector } from 'react-redux' import classNames from 'classnames' import { routerContext, RouterContextData } from '~/libs/core' @@ -14,45 +14,25 @@ import '../../styles/global/_index.scss' import styles from './styles.module.scss' -const OnboardingFooterContent: FC<{ - fetchMemberInfo: () => void - fetchMemberTraits: () => void - reduxMemberInfo: Member | undefined -}> = props => { +const OnboardingContent: FC<{ +}> = () => { + const { getChildRoutes }: RouterContextData = useContext(routerContext) + const location = useLocation() + const dispatch = useDispatch() + const reduxMemberInfo: Member = useSelector((state: any) => state.member.memberInfo) + useEffect(() => { - props.fetchMemberInfo() - props.fetchMemberTraits() + dispatch(fetchMemberInfo()) + dispatch(fetchMemberTraits()) /* eslint-disable react-hooks/exhaustive-deps */ }, []) - return ( - - I will complete this onboarding later, - skip for now - . - + useEffect( + () => { + window.scrollTo(0, 0) + }, + [location.pathname], ) -} - -const mapStateToProps: any = (state: any) => { - const { - memberInfo, - }: any = state.member - - return { - reduxMemberInfo: memberInfo, - } -} - -const mapDispatchToProps: any = { - fetchMemberInfo, - fetchMemberTraits, -} -const OnboardingFooter: any = connect(mapStateToProps, mapDispatchToProps)(OnboardingFooterContent) - -const OnboardingContent: FC<{ -}> = () => { - const { getChildRoutes }: RouterContextData = useContext(routerContext) return ( <> @@ -61,9 +41,12 @@ const OnboardingContent: FC<{ {getChildRoutes(onboardRouteId)} -
- + + I will complete this onboarding later, + skip for now + . + ) } diff --git a/src/apps/onboarding/src/styles/global/_color.scss b/src/apps/onboarding/src/styles/global/_color.scss index 2ebc44d1d..28e6e893a 100644 --- a/src/apps/onboarding/src/styles/global/_color.scss +++ b/src/apps/onboarding/src/styles/global/_color.scss @@ -5,3 +5,7 @@ .color-black-60 { color: $black-60; } + +.color-red-120 { + color: $red-120; +}