diff --git a/src/components/Admin/resources/cms/post/PostList.tsx b/src/components/Admin/resources/cms/post/PostList.tsx index 909746c5..1b043821 100644 --- a/src/components/Admin/resources/cms/post/PostList.tsx +++ b/src/components/Admin/resources/cms/post/PostList.tsx @@ -1,5 +1,5 @@ import {FC} from 'react' -import {Datagrid, DateField, FunctionField, List, NumberField, RaRecord, TextField} from 'react-admin' +import {Datagrid, DateField, FunctionField, List, RaRecord, TextField} from 'react-admin' import {SitesArrayField} from '@/components/Admin/custom/SitesArrayField' import {TruncatedTextField} from '@/components/Admin/custom/TruncatedTextField' diff --git a/src/components/PageLayout/LoginFormWrapper/LoginFormWrapper.tsx b/src/components/PageLayout/LoginFormWrapper/LoginFormWrapper.tsx index e58e7596..d2e4cb56 100644 --- a/src/components/PageLayout/LoginFormWrapper/LoginFormWrapper.tsx +++ b/src/components/PageLayout/LoginFormWrapper/LoginFormWrapper.tsx @@ -3,6 +3,7 @@ import {useRouter} from 'next/router' import {FC, useState} from 'react' import {Button} from '@/components/Clickable/Button' +import {useSeminarInfo} from '@/utils/useSeminarInfo' import {LoginForm} from '../LoginForm/LoginForm' import {PasswordResetRequestForm} from '../PasswordResetRequest/PasswordResetRequest' @@ -15,24 +16,28 @@ export const LoginFormWrapper: FC = ({closeOverlay}) => { const router = useRouter() const [form, changeForm] = useState('login') + const {seminar} = useSeminarInfo() + if (form === 'login') return ( - + - + + + ) return ( { - router.push('/verifikacia') + router.push(`/${seminar}/reset-sent`) }} /> ) diff --git a/src/components/PageLayout/PasswordResetRequest/PasswordResetRequest.tsx b/src/components/PageLayout/PasswordResetRequest/PasswordResetRequest.tsx index 2d6f2eef..3ed8f952 100644 --- a/src/components/PageLayout/PasswordResetRequest/PasswordResetRequest.tsx +++ b/src/components/PageLayout/PasswordResetRequest/PasswordResetRequest.tsx @@ -1,3 +1,4 @@ +import {Stack} from '@mui/material' import {useMutation} from '@tanstack/react-query' import axios from 'axios' import {FC} from 'react' @@ -24,11 +25,9 @@ export const PasswordResetRequestForm: FC = ({closeOverla const {mutate: submitFormData} = useMutation({ mutationFn: (data: PasswordResetRequestFormValues) => { - return axios.post('/api/user/password/reset/', data) + return axios.post('/api/user/password/reset', data) }, - onError: (error, variables, context) => {}, - onSuccess: () => { closeOverlay() }, @@ -40,19 +39,25 @@ export const PasswordResetRequestForm: FC = ({closeOverla return (
- - + + + + + + ) } diff --git a/src/components/PasswordReset/PasswordReset.tsx b/src/components/PasswordReset/PasswordReset.tsx new file mode 100644 index 00000000..ffba07a7 --- /dev/null +++ b/src/components/PasswordReset/PasswordReset.tsx @@ -0,0 +1,103 @@ +import {Stack, Typography} from '@mui/material' +import {useMutation} from '@tanstack/react-query' +import axios from 'axios' +import {useRouter} from 'next/router' +import {FC} from 'react' +import {SubmitHandler, useForm} from 'react-hook-form' + +import {Button} from '@/components/Clickable/Button' +import {FormInput} from '@/components/FormItems/FormInput/FormInput' +import {IGeneralPostResponse} from '@/types/api/general' + +import {LoginForm} from '../PageLayout/LoginForm/LoginForm' + +export type PasswordResetFormProps = { + uid: string + token: string +} + +type PasswordResetForm = { + password1: string + password2: string +} + +const defaultValues: PasswordResetForm = { + password1: '', + password2: '', +} + +export const PasswordResetForm: FC = ({uid, token}) => { + const router = useRouter() + + const {handleSubmit, control, getValues} = useForm({defaultValues}) + + const requiredRule = {required: '* Toto pole nemôže byť prázdne.'} + + const transformFormData = (data: PasswordResetForm) => { + return { + new_password1: data.password1, + new_password2: data.password2, + uid: uid, + token: token, + } + } + + const {mutate: submitFormData, isSuccess: isReset} = useMutation({ + mutationFn: (data: PasswordResetForm) => { + return axios.post('/api/user/password/reset/confirm', transformFormData(data)) + }, + }) + + const onSubmit: SubmitHandler = (data) => { + submitFormData(data) + } + + if (isReset) + return ( + + Heslo úspešne zmenené, môžeš sa prihlásiť + { + router.push('/') + }} + /> + + ) + + return ( +
+ + + { + if (val !== getValues().password1) return '* Zadané heslá sa nezhodujú.' + }, + }} + /> + + + + +
+ ) +} diff --git a/src/components/PasswordResetSent/PasswordResetSent.tsx b/src/components/PasswordResetSent/PasswordResetSent.tsx new file mode 100644 index 00000000..b079954c --- /dev/null +++ b/src/components/PasswordResetSent/PasswordResetSent.tsx @@ -0,0 +1,10 @@ +import {Typography} from '@mui/material' +import {FC} from 'react' + +export const PasswordResetSent: FC = () => { + return ( + + Ak existuje účet so zadaným e-mailom, poslali sme ti naňho link pre zmenu hesla. + + ) +} diff --git a/src/components/Posts/Post.tsx b/src/components/Posts/Post.tsx index 952a3b5b..9c9ae050 100644 --- a/src/components/Posts/Post.tsx +++ b/src/components/Posts/Post.tsx @@ -18,7 +18,7 @@ export interface IPost { sites: number[] } -export const Post: FC = ({id, caption, short_text, links, sites, added_at}) => { +export const Post: FC = ({caption, short_text, links, sites, added_at}) => { const {seminarId} = useSeminarInfo() if (!sites.includes(seminarId)) return null diff --git a/src/components/Verification/Verification.tsx b/src/components/Verification/Verification.tsx index b916cada..daff59ec 100644 --- a/src/components/Verification/Verification.tsx +++ b/src/components/Verification/Verification.tsx @@ -1,5 +1,6 @@ +import {Typography} from '@mui/material' import {FC} from 'react' export const Verification: FC = () => { - return
Verifikačný e-mail bol odoslaný na zadanú e-mailovú adresu.
+ return Verifikačný e-mail bol odoslaný na zadanú e-mailovú adresu. } diff --git a/src/pages/malynar/reset-sent/index.tsx b/src/pages/malynar/reset-sent/index.tsx new file mode 100644 index 00000000..ae458357 --- /dev/null +++ b/src/pages/malynar/reset-sent/index.tsx @@ -0,0 +1,9 @@ +import {NextPage} from 'next' + +import Page from '../../strom/reset-sent/index' + +const Verifikacia: NextPage = () => { + return +} + +export default Verifikacia diff --git a/src/pages/malynar/verifikacia/[[...params]].tsx b/src/pages/malynar/verifikacia/[[...params]].tsx index 7727865e..3a39698d 100644 --- a/src/pages/malynar/verifikacia/[[...params]].tsx +++ b/src/pages/malynar/verifikacia/[[...params]].tsx @@ -1,6 +1,7 @@ import {NextPage} from 'next' -import {PageLayout} from '../../../components/PageLayout/PageLayout' +import {PageLayout} from '@/components/PageLayout/PageLayout' + import {Verification} from '../../../components/Verification/Verification' const Verifikacia: NextPage = () => { diff --git a/src/pages/matik/reset-sent/index.tsx b/src/pages/matik/reset-sent/index.tsx new file mode 100644 index 00000000..ae458357 --- /dev/null +++ b/src/pages/matik/reset-sent/index.tsx @@ -0,0 +1,9 @@ +import {NextPage} from 'next' + +import Page from '../../strom/reset-sent/index' + +const Verifikacia: NextPage = () => { + return +} + +export default Verifikacia diff --git a/src/pages/matik/verifikacia/[[...params]].tsx b/src/pages/matik/verifikacia/[[...params]].tsx index 7727865e..3a39698d 100644 --- a/src/pages/matik/verifikacia/[[...params]].tsx +++ b/src/pages/matik/verifikacia/[[...params]].tsx @@ -1,6 +1,7 @@ import {NextPage} from 'next' -import {PageLayout} from '../../../components/PageLayout/PageLayout' +import {PageLayout} from '@/components/PageLayout/PageLayout' + import {Verification} from '../../../components/Verification/Verification' const Verifikacia: NextPage = () => { diff --git a/src/pages/strom/archiv/[[...params]].tsx b/src/pages/strom/archiv/[[...params]].tsx index 7bb94415..43f26130 100644 --- a/src/pages/strom/archiv/[[...params]].tsx +++ b/src/pages/strom/archiv/[[...params]].tsx @@ -1,7 +1,8 @@ import {NextPage} from 'next' +import {PageLayout} from '@/components/PageLayout/PageLayout' + import {Archive} from '../../../components/Archive/Archive' -import {PageLayout} from '../../../components/PageLayout/PageLayout' const Archiv: NextPage = () => { return ( diff --git a/src/pages/strom/reset-password/[...resetToken].tsx b/src/pages/strom/reset-password/[...resetToken].tsx new file mode 100644 index 00000000..1f0af4a8 --- /dev/null +++ b/src/pages/strom/reset-password/[...resetToken].tsx @@ -0,0 +1,31 @@ +import {NextPage} from 'next' + +import {PageLayout} from '@/components/PageLayout/PageLayout' +import {PasswordResetForm, PasswordResetFormProps} from '@/components/PasswordReset/PasswordReset' + +type QueryType = { + query?: { + resetToken: string | string[] + } +} + +const Verify: NextPage = ({uid, token}) => ( + + + +) + +export default Verify + +export const getServerSideProps = async ({query}: QueryType) => { + const errorRedirect = {redirect: {destination: '/', permanent: false}} + + if (query?.resetToken && Array.isArray(query.resetToken) && query.resetToken.length === 2) { + const token = query.resetToken[0] + const uid = query.resetToken[1] + + if (typeof token === 'string' && typeof uid === 'string') return {props: {uid: uid, token: token}} + } + + return errorRedirect +} diff --git a/src/pages/strom/reset-sent/index.tsx b/src/pages/strom/reset-sent/index.tsx new file mode 100644 index 00000000..6790a4fe --- /dev/null +++ b/src/pages/strom/reset-sent/index.tsx @@ -0,0 +1,14 @@ +import {NextPage} from 'next' + +import {PageLayout} from '@/components/PageLayout/PageLayout' +import {PasswordResetSent} from '@/components/PasswordResetSent/PasswordResetSent' + +const Verifikacia: NextPage = () => { + return ( + + + + ) +} + +export default Verifikacia diff --git a/src/pages/strom/verifikacia/[[...params]].tsx b/src/pages/strom/verifikacia/[[...params]].tsx index 7727865e..3a39698d 100644 --- a/src/pages/strom/verifikacia/[[...params]].tsx +++ b/src/pages/strom/verifikacia/[[...params]].tsx @@ -1,6 +1,7 @@ import {NextPage} from 'next' -import {PageLayout} from '../../../components/PageLayout/PageLayout' +import {PageLayout} from '@/components/PageLayout/PageLayout' + import {Verification} from '../../../components/Verification/Verification' const Verifikacia: NextPage = () => {