| import { | import { | ||||
| Alert, | |||||
| Box, | Box, | ||||
| Button, | Button, | ||||
| Container, | Container, | ||||
| Grid, | Grid, | ||||
| Snackbar, | |||||
| TextField, | TextField, | ||||
| Typography, | Typography, | ||||
| } from '@mui/material'; | } from '@mui/material'; | ||||
| import { useTranslation } from 'next-i18next'; | import { useTranslation } from 'next-i18next'; | ||||
| import Link from 'next/link'; | import Link from 'next/link'; | ||||
| import PropType from 'prop-types'; | import PropType from 'prop-types'; | ||||
| import React from 'react'; | |||||
| import React, { useState } from 'react'; | |||||
| import { BASE_PAGE } from '../../../constants/pages'; | import { BASE_PAGE } from '../../../constants/pages'; | ||||
| import { postQuestion } from '../../../requests/question/postQuestionRequest'; | import { postQuestion } from '../../../requests/question/postQuestionRequest'; | ||||
| import { contactPageSchema } from '../../../schemas/contactSchema'; | import { contactPageSchema } from '../../../schemas/contactSchema'; | ||||
| const ContactPageForm = () => { | const ContactPageForm = () => { | ||||
| const { t } = useTranslation('forms', 'contact', 'common'); | const { t } = useTranslation('forms', 'contact', 'common'); | ||||
| const [open, setOpen] = useState(false); | |||||
| //const [error] = useState({ hasError: false, errorMessage: '' }); | //const [error] = useState({ hasError: false, errorMessage: '' }); | ||||
| const handleSubmit = async (values) => { | const handleSubmit = async (values) => { | ||||
| try { | try { | ||||
| postQuestion(values); | postQuestion(values); | ||||
| setOpen(true); | |||||
| } catch (error) { | } catch (error) { | ||||
| console.log(error); | console.log(error); | ||||
| } | } | ||||
| }; | }; | ||||
| const handleCloseNotification = () => { | |||||
| setOpen(false); | |||||
| }; | |||||
| const formik = useFormik({ | const formik = useFormik({ | ||||
| initialValues: { | initialValues: { | ||||
| firstName: '', | firstName: '', | ||||
| return ( | return ( | ||||
| <Container component="main" maxWidth="md" sx={{ mb: '60px' }}> | <Container component="main" maxWidth="md" sx={{ mb: '60px' }}> | ||||
| <Snackbar | |||||
| anchorOrigin={{ vertical: 'top', horizontal: 'center' }} | |||||
| open={open} | |||||
| autoHideDuration={3000} | |||||
| onClose={handleCloseNotification} | |||||
| > | |||||
| <Alert | |||||
| onClose={handleCloseNotification} | |||||
| severity="success" | |||||
| sx={{ width: '100%', backgroundColor: 'green', color: 'white' }} | |||||
| > | |||||
| Question submitted! | |||||
| </Alert> | |||||
| </Snackbar> | |||||
| <Box | <Box | ||||
| sx={{ | sx={{ | ||||
| marginTop: 32, | marginTop: 32, |
| import { Grid, Typography } from '@mui/material'; | |||||
| import { Alert, Grid, Snackbar, Typography } from '@mui/material'; | |||||
| import { Box } from '@mui/system'; | import { Box } from '@mui/system'; | ||||
| import { useSession } from 'next-auth/react'; | import { useSession } from 'next-auth/react'; | ||||
| import { useState } from 'react'; | import { useState } from 'react'; | ||||
| const { data: session } = useSession(); | const { data: session } = useSession(); | ||||
| const { updateUserInfo } = useUserUpdate(); | const { updateUserInfo } = useUserUpdate(); | ||||
| const [enableBtn, setEnableBtn] = useState(true); | const [enableBtn, setEnableBtn] = useState(true); | ||||
| const [open, setOpen] = useState(false); | |||||
| const updateUserHandler = async (values) => { | const updateUserHandler = async (values) => { | ||||
| try { | try { | ||||
| setEnableBtn(false); | setEnableBtn(false); | ||||
| updateUserInfo(values); | updateUserInfo(values); | ||||
| await updateUser(values, session.user._id); | await updateUser(values, session.user._id); | ||||
| setOpen(true); | |||||
| setTimeout(() => { | |||||
| setEnableBtn(true); | |||||
| }, 5000); | |||||
| } catch (error) { | } catch (error) { | ||||
| console.log(error); | console.log(error); | ||||
| setTimeout(() => { | setTimeout(() => { | ||||
| } | } | ||||
| }; | }; | ||||
| const handleCloseNotification = () => { | |||||
| setOpen(false); | |||||
| }; | |||||
| const mapOrdersToDom = () => | const mapOrdersToDom = () => | ||||
| orders.slice(-4).map((order, i) => ( | orders.slice(-4).map((order, i) => ( | ||||
| <OrderCard | <OrderCard | ||||
| return ( | return ( | ||||
| <Grid container spacing={2} sx={{ py: 10, height: '100%', width: '100%' }}> | <Grid container spacing={2} sx={{ py: 10, height: '100%', width: '100%' }}> | ||||
| <Snackbar | |||||
| anchorOrigin={{ vertical: 'top', horizontal: 'center' }} | |||||
| open={open} | |||||
| autoHideDuration={3000} | |||||
| onClose={handleCloseNotification} | |||||
| > | |||||
| <Alert | |||||
| onClose={handleCloseNotification} | |||||
| severity="success" | |||||
| sx={{ width: '100%', backgroundColor: 'green', color: 'white' }} | |||||
| > | |||||
| User profile updated! | |||||
| </Alert> | |||||
| </Snackbar> | |||||
| <Grid item xs={12}> | <Grid item xs={12}> | ||||
| <Typography | <Typography | ||||
| variant="h3" | variant="h3" |
| }, | }, | ||||
| email: { | email: { | ||||
| type: String, | type: String, | ||||
| unique: [true, 'Email must be unique.'], | |||||
| required: [true, 'Please provide an email.'], | required: [true, 'Please provide an email.'], | ||||
| trim: true, | trim: true, | ||||
| lowercase: true, | lowercase: true, | ||||
| unique: false, | |||||
| validate(value) { | validate(value) { | ||||
| if (!validator.isEmail(value)) { | if (!validator.isEmail(value)) { | ||||
| throw new Error('Email is invalid'); | throw new Error('Email is invalid'); |