Update SignupModal and LoginModal to use Dialog
This commit is contained in:
parent
7c36aac130
commit
94f5f69412
3 changed files with 111 additions and 109 deletions
|
|
@ -22,6 +22,7 @@
|
|||
display: flex;
|
||||
align-items: center;
|
||||
gap: $unit;
|
||||
justify-content: space-between;
|
||||
|
||||
.left {
|
||||
display: flex;
|
||||
|
|
@ -38,6 +39,7 @@
|
|||
|
||||
.DialogClose {
|
||||
background: transparent;
|
||||
border: none;
|
||||
|
||||
&:hover {
|
||||
cursor: pointer;
|
||||
|
|
@ -58,7 +60,13 @@
|
|||
.DialogTitle {
|
||||
color: var(--text-primary);
|
||||
font-size: $font-xlarge;
|
||||
flex-grow: 1;
|
||||
|
||||
h1 {
|
||||
color: var(--text-primary);
|
||||
font-size: $font-xlarge;
|
||||
font-weight: $medium;
|
||||
text-align: left;
|
||||
}
|
||||
}
|
||||
|
||||
.DialogTop {
|
||||
|
|
|
|||
|
|
@ -4,13 +4,17 @@ import Router, { useRouter } from 'next/router'
|
|||
import { useTranslation } from 'react-i18next'
|
||||
import { AxiosResponse } from 'axios'
|
||||
|
||||
import * as Dialog from '@radix-ui/react-dialog'
|
||||
|
||||
import api from '~utils/api'
|
||||
import { accountState } from '~utils/accountState'
|
||||
|
||||
import Button from '~components/Button'
|
||||
import Input from '~components/Input'
|
||||
import {
|
||||
Dialog,
|
||||
DialogTrigger,
|
||||
DialogContent,
|
||||
DialogClose,
|
||||
} from '~components/Dialog'
|
||||
|
||||
import CrossIcon from '~public/icons/Cross.svg'
|
||||
import './index.scss'
|
||||
|
|
@ -99,7 +103,7 @@ const LoginModal = (props: Props) => {
|
|||
.login(body)
|
||||
.then((response) => {
|
||||
storeCookieInfo(response)
|
||||
return response.data.id
|
||||
return response.data.user.id
|
||||
})
|
||||
.then((id) => fetchUserInfo(id))
|
||||
.then((infoResponse) => storeUserInfo(infoResponse))
|
||||
|
|
@ -111,12 +115,12 @@ const LoginModal = (props: Props) => {
|
|||
}
|
||||
|
||||
function storeCookieInfo(response: AxiosResponse) {
|
||||
const user = response.data
|
||||
const resp = response.data
|
||||
|
||||
const cookieObj: AccountCookie = {
|
||||
userId: user.id,
|
||||
username: user.username,
|
||||
token: response.data.access_token,
|
||||
userId: resp.user.id,
|
||||
username: resp.user.username,
|
||||
token: resp.access_token,
|
||||
}
|
||||
|
||||
setCookie('account', cookieObj, { path: '/' })
|
||||
|
|
@ -165,51 +169,44 @@ const LoginModal = (props: Props) => {
|
|||
}
|
||||
|
||||
return (
|
||||
<Dialog.Root open={open} onOpenChange={openChange}>
|
||||
<Dialog.Trigger asChild>
|
||||
<Dialog open={open} onOpenChange={openChange}>
|
||||
<DialogTrigger asChild>
|
||||
<li className="MenuItem">
|
||||
<span>{t('menu.login')}</span>
|
||||
</li>
|
||||
</Dialog.Trigger>
|
||||
<Dialog.Portal>
|
||||
<Dialog.Content
|
||||
className="Login Dialog"
|
||||
onOpenAutoFocus={(event) => event.preventDefault()}
|
||||
>
|
||||
<div className="DialogHeader">
|
||||
<Dialog.Title className="DialogTitle">
|
||||
{t('modals.login.title')}
|
||||
</Dialog.Title>
|
||||
<Dialog.Close className="DialogClose" asChild>
|
||||
<span>
|
||||
<CrossIcon />
|
||||
</span>
|
||||
</Dialog.Close>
|
||||
</DialogTrigger>
|
||||
<DialogContent className="Login Dialog">
|
||||
<div className="DialogHeader">
|
||||
<div className="DialogTitle">
|
||||
<h1>{t('modals.login.title')}</h1>
|
||||
</div>
|
||||
<DialogClose className="DialogClose">
|
||||
<CrossIcon />
|
||||
</DialogClose>
|
||||
</div>
|
||||
|
||||
<form className="form" onSubmit={login}>
|
||||
<Input
|
||||
name="email"
|
||||
placeholder={t('modals.login.placeholders.email')}
|
||||
onChange={handleChange}
|
||||
error={errors.email}
|
||||
ref={emailInput}
|
||||
/>
|
||||
<form className="form" onSubmit={login}>
|
||||
<Input
|
||||
name="email"
|
||||
placeholder={t('modals.login.placeholders.email')}
|
||||
onChange={handleChange}
|
||||
error={errors.email}
|
||||
ref={emailInput}
|
||||
/>
|
||||
|
||||
<Input
|
||||
name="password"
|
||||
placeholder={t('modals.login.placeholders.password')}
|
||||
onChange={handleChange}
|
||||
error={errors.password}
|
||||
ref={passwordInput}
|
||||
/>
|
||||
<Input
|
||||
name="password"
|
||||
placeholder={t('modals.login.placeholders.password')}
|
||||
type="password"
|
||||
onChange={handleChange}
|
||||
error={errors.password}
|
||||
ref={passwordInput}
|
||||
/>
|
||||
|
||||
<Button>{t('modals.login.buttons.confirm')}</Button>
|
||||
</form>
|
||||
</Dialog.Content>
|
||||
<Dialog.Overlay className="Overlay" />
|
||||
</Dialog.Portal>
|
||||
</Dialog.Root>
|
||||
<Button text={t('modals.login.buttons.confirm')} />
|
||||
</form>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,13 +5,17 @@ import { useRouter } from 'next/router'
|
|||
import { Trans, useTranslation } from 'next-i18next'
|
||||
import { AxiosResponse } from 'axios'
|
||||
|
||||
import * as Dialog from '@radix-ui/react-dialog'
|
||||
|
||||
import api from '~utils/api'
|
||||
import { accountState } from '~utils/accountState'
|
||||
|
||||
import Button from '~components/Button'
|
||||
import Input from '~components/Input'
|
||||
import {
|
||||
Dialog,
|
||||
DialogTrigger,
|
||||
DialogContent,
|
||||
DialogClose,
|
||||
} from '~components/Dialog'
|
||||
|
||||
import CrossIcon from '~public/icons/Cross.svg'
|
||||
import './index.scss'
|
||||
|
|
@ -75,19 +79,19 @@ const SignupModal = (props: Props) => {
|
|||
.create(body)
|
||||
.then((response) => {
|
||||
storeCookieInfo(response)
|
||||
return response.data.user_id
|
||||
return response.data.id
|
||||
})
|
||||
.then((id) => fetchUserInfo(id))
|
||||
.then((infoResponse) => storeUserInfo(infoResponse))
|
||||
}
|
||||
|
||||
function storeCookieInfo(response: AxiosResponse) {
|
||||
const user = response.data.user
|
||||
const resp = response.data
|
||||
|
||||
const cookieObj: AccountCookie = {
|
||||
userId: user.user_id,
|
||||
username: user.username,
|
||||
token: user.token,
|
||||
userId: resp.id,
|
||||
username: resp.username,
|
||||
token: resp.token,
|
||||
}
|
||||
|
||||
setCookie('account', cookieObj, { path: '/' })
|
||||
|
|
@ -99,7 +103,6 @@ const SignupModal = (props: Props) => {
|
|||
|
||||
function storeUserInfo(response: AxiosResponse) {
|
||||
const user = response.data
|
||||
console.log(user)
|
||||
|
||||
const cookieObj: UserCookie = {
|
||||
picture: user.avatar.picture,
|
||||
|
|
@ -252,73 +255,67 @@ const SignupModal = (props: Props) => {
|
|||
}
|
||||
|
||||
return (
|
||||
<Dialog.Root open={open} onOpenChange={openChange}>
|
||||
<Dialog.Trigger asChild>
|
||||
<Dialog open={open} onOpenChange={openChange}>
|
||||
<DialogTrigger asChild>
|
||||
<li className="MenuItem">
|
||||
<span>{t('menu.signup')}</span>
|
||||
</li>
|
||||
</Dialog.Trigger>
|
||||
<Dialog.Portal>
|
||||
<Dialog.Content
|
||||
className="Signup Dialog"
|
||||
onOpenAutoFocus={(event) => event.preventDefault()}
|
||||
>
|
||||
<div className="DialogHeader">
|
||||
<Dialog.Title className="DialogTitle">
|
||||
{t('modals.signup.title')}
|
||||
</Dialog.Title>
|
||||
<Dialog.Close className="DialogClose" asChild>
|
||||
<span>
|
||||
<CrossIcon />
|
||||
</span>
|
||||
</Dialog.Close>
|
||||
</DialogTrigger>
|
||||
<DialogContent className="Signup Dialog">
|
||||
<div className="DialogHeader">
|
||||
<div className="DialogTitle">
|
||||
<h1>{t('modals.signup.title')}</h1>
|
||||
</div>
|
||||
<DialogClose className="DialogClose">
|
||||
<CrossIcon />
|
||||
</DialogClose>
|
||||
</div>
|
||||
|
||||
<form className="form" onSubmit={register}>
|
||||
<Input
|
||||
name="username"
|
||||
placeholder={t('modals.signup.placeholders.username')}
|
||||
onChange={handleNameChange}
|
||||
error={errors.username}
|
||||
ref={usernameInput}
|
||||
/>
|
||||
<form className="form" onSubmit={register}>
|
||||
<Input
|
||||
name="username"
|
||||
placeholder={t('modals.signup.placeholders.username')}
|
||||
onChange={handleNameChange}
|
||||
error={errors.username}
|
||||
ref={usernameInput}
|
||||
/>
|
||||
|
||||
<Input
|
||||
name="email"
|
||||
placeholder={t('modals.signup.placeholders.email')}
|
||||
onChange={handleNameChange}
|
||||
error={errors.email}
|
||||
ref={emailInput}
|
||||
/>
|
||||
<Input
|
||||
name="email"
|
||||
placeholder={t('modals.signup.placeholders.email')}
|
||||
onChange={handleNameChange}
|
||||
error={errors.email}
|
||||
ref={emailInput}
|
||||
/>
|
||||
|
||||
<Input
|
||||
name="password"
|
||||
placeholder={t('modals.signup.placeholders.password')}
|
||||
onChange={handlePasswordChange}
|
||||
error={errors.password}
|
||||
ref={passwordInput}
|
||||
/>
|
||||
<Input
|
||||
name="password"
|
||||
placeholder={t('modals.signup.placeholders.password')}
|
||||
type="password"
|
||||
onChange={handlePasswordChange}
|
||||
error={errors.password}
|
||||
ref={passwordInput}
|
||||
/>
|
||||
|
||||
<Input
|
||||
name="confirm_password"
|
||||
placeholder={t('modals.signup.placeholders.password_confirm')}
|
||||
onChange={handlePasswordChange}
|
||||
error={errors.passwordConfirmation}
|
||||
ref={passwordConfirmationInput}
|
||||
/>
|
||||
<Input
|
||||
name="confirm_password"
|
||||
placeholder={t('modals.signup.placeholders.password_confirm')}
|
||||
type="password"
|
||||
onChange={handlePasswordChange}
|
||||
error={errors.passwordConfirmation}
|
||||
ref={passwordConfirmationInput}
|
||||
/>
|
||||
|
||||
<Button>{t('modals.signup.buttons.confirm')}</Button>
|
||||
<Button text={t('modals.signup.buttons.confirm')} />
|
||||
|
||||
<Dialog.Description className="terms">
|
||||
{/* <Trans i18nKey="modals.signup.agreement">
|
||||
<p className="terms">
|
||||
{/* <Trans i18nKey="modals.signup.agreement">
|
||||
By signing up, I agree to the <Link href="/privacy"><span>Privacy Policy</span></Link><Link href="/usage"><span>Usage Guidelines</span></Link>.
|
||||
</Trans> */}
|
||||
</Dialog.Description>
|
||||
</form>
|
||||
</Dialog.Content>
|
||||
<Dialog.Overlay className="Overlay" />
|
||||
</Dialog.Portal>
|
||||
</Dialog.Root>
|
||||
</p>
|
||||
</form>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue