2023-03-14 11:00:40 +00:00
import styled from "@emotion/styled" ;
import { Button , Modal , PasswordInput , TextInput } from "@mantine/core" ;
2023-04-15 10:30:02 +00:00
import { useCallback } from "react" ;
2023-03-16 19:06:29 +00:00
import { FormattedMessage , useIntl } from "react-intl" ;
2023-04-15 10:30:02 +00:00
import { useAppDispatch , useAppSelector } from "../store" ;
import { closeModals , openLoginModal , openSignupModal , selectModal } from "../store/ui" ;
2023-03-14 11:00:40 +00:00
const Container = styled . form `
* {
font-family: "Work Sans", sans-serif;
}
h2 {
font-size: 1.5rem;
font-weight: bold;
}
.mantine-TextInput-root, .mantine-PasswordInput-root {
margin-top: 1rem;
}
.mantine-TextInput-root + .mantine-Button-root,
.mantine-PasswordInput-root + .mantine-Button-root {
margin-top: 1.618rem;
}
.mantine-Button-root {
margin-top: 1rem;
}
label {
margin-bottom: 0.25rem;
}
` ;
export function LoginModal ( props : any ) {
const modal = useAppSelector ( selectModal );
const dispatch = useAppDispatch ();
2023-03-16 19:06:29 +00:00
const intl = useIntl ();
2023-03-14 11:00:40 +00:00
const onClose = useCallback (() => dispatch ( closeModals ()), [ dispatch ]);
const onCreateAccountClick = useCallback (() => dispatch ( openSignupModal ()), [ dispatch ]);
return < Modal opened = { modal === 'login' } onClose = { onClose } withCloseButton = { false }>
< Container action = "/chatapi/login" method = "post" >
< h2 >
2023-03-16 19:06:29 +00:00
< FormattedMessage defaultMessage = { "Sign in" } />
2023-03-14 11:00:40 +00:00
</ h2 >
< input type = "hidden" name = "redirect_url" value = { window . location . href } />
2023-03-16 19:06:29 +00:00
< TextInput
label = { intl . formatMessage ({ defaultMessage : "Email address" })}
2023-03-14 11:00:40 +00:00
name = "username"
2023-03-16 19:06:29 +00:00
placeholder = { intl . formatMessage ({ defaultMessage : "Enter your email address" })}
2023-03-14 11:00:40 +00:00
type = "email"
required />
2023-03-16 19:06:29 +00:00
< PasswordInput
label = { intl . formatMessage ({ defaultMessage : "Password" })}
2023-03-14 11:00:40 +00:00
name = "password"
2023-03-16 19:06:29 +00:00
placeholder = { intl . formatMessage ({ defaultMessage : "Enter your password" })}
2023-03-14 11:00:40 +00:00
maxLength = { 500 }
required />
< Button fullWidth type = "submit" >
2023-03-16 19:06:29 +00:00
< FormattedMessage defaultMessage = { "Sign in" } />
2023-03-14 11:00:40 +00:00
</ Button >
< Button fullWidth variant = "subtle" onClick = { onCreateAccountClick }>
2023-03-16 20:05:45 +00:00
< FormattedMessage defaultMessage = { "Or create an account" } description = "Label for a button on the Sign In page that lets the user create an account instead" />
2023-03-14 11:00:40 +00:00
</ Button >
</ Container >
</ Modal >
}
export function CreateAccountModal ( props : any ) {
const modal = useAppSelector ( selectModal );
const dispatch = useAppDispatch ();
2023-03-16 19:06:29 +00:00
const intl = useIntl ();
2023-03-14 11:00:40 +00:00
const onClose = useCallback (() => dispatch ( closeModals ()), [ dispatch ]);
const onSignInClick = useCallback (() => dispatch ( openLoginModal ()), [ dispatch ]);
return < Modal opened = { modal === 'signup' } onClose = { onClose } withCloseButton = { false }>
< Container action = "/chatapi/register" method = "post" >
< h2 >
2023-03-16 19:06:29 +00:00
< FormattedMessage defaultMessage = { "Create an account" } />
2023-03-14 11:00:40 +00:00
</ h2 >
< input type = "hidden" name = "redirect_url" value = { window . location . href } />
2023-03-16 19:06:29 +00:00
< TextInput
label = { intl . formatMessage ({ defaultMessage : "Email address" })}
2023-03-14 11:00:40 +00:00
name = "username"
2023-03-16 19:06:29 +00:00
placeholder = { intl . formatMessage ({ defaultMessage : "Enter your email address" })}
2023-03-14 11:00:40 +00:00
type = "email"
required />
2023-03-16 19:06:29 +00:00
< PasswordInput
label = { intl . formatMessage ({ defaultMessage : "Password" })}
2023-03-14 11:00:40 +00:00
name = "password"
2023-03-16 19:06:29 +00:00
placeholder = { intl . formatMessage ({ defaultMessage : "Enter your password" })}
2023-03-14 11:00:40 +00:00
minLength = { 6 }
maxLength = { 500 }
required />
< Button fullWidth type = "submit" >
2023-03-16 19:06:29 +00:00
< FormattedMessage defaultMessage = { "Sign up" } />
2023-03-14 11:00:40 +00:00
</ Button >
< Button fullWidth variant = "subtle" onClick = { onSignInClick }>
2023-03-16 20:05:45 +00:00
< FormattedMessage defaultMessage = { "Or sign in to an existing account" } description = "Label for a button on the Create Account page that lets the user sign into their existing account instead" />
2023-03-14 11:00:40 +00:00
</ Button >
</ Container >
</ Modal >
}