Setup page converted to chakra
Fixed locale js error Setup and login forms consistent
This commit is contained in:
parent
f416ff9afe
commit
8b215340e5
6 changed files with 154 additions and 157 deletions
|
@ -59,17 +59,7 @@ function Footer() {
|
||||||
defaultMessage: "Copyright © {year} jc21.com",
|
defaultMessage: "Copyright © {year} jc21.com",
|
||||||
},
|
},
|
||||||
{ year: new Date().getFullYear() },
|
{ year: new Date().getFullYear() },
|
||||||
)}{" "}
|
)}
|
||||||
<a
|
|
||||||
className="link-secondary"
|
|
||||||
href="https://preview.tabler.io/"
|
|
||||||
target="_blank"
|
|
||||||
rel="noreferrer">
|
|
||||||
{intl.formatMessage({
|
|
||||||
id: "footer.theme",
|
|
||||||
defaultMessage: "Theme by Tabler",
|
|
||||||
})}
|
|
||||||
</a>
|
|
||||||
</li>
|
</li>
|
||||||
<li className="list-inline-item">
|
<li className="list-inline-item">
|
||||||
<a
|
<a
|
||||||
|
|
|
@ -29,8 +29,10 @@ export const LocalePicker: React.FC<LocalPickerProps> = ({
|
||||||
}) => {
|
}) => {
|
||||||
const { locale, setLocale } = useLocaleState();
|
const { locale, setLocale } = useLocaleState();
|
||||||
|
|
||||||
|
// first item of each array should be the language code,
|
||||||
|
// not the country code
|
||||||
const options = [
|
const options = [
|
||||||
["us", "en-US"],
|
["en", "en-US"],
|
||||||
["de", "de-DE"],
|
["de", "de-DE"],
|
||||||
["fa", "fa-IR"],
|
["fa", "fa-IR"],
|
||||||
];
|
];
|
||||||
|
|
|
@ -41,9 +41,6 @@
|
||||||
"footer.github": {
|
"footer.github": {
|
||||||
"defaultMessage": "Github"
|
"defaultMessage": "Github"
|
||||||
},
|
},
|
||||||
"footer.theme": {
|
|
||||||
"defaultMessage": "Theme by Tabler"
|
|
||||||
},
|
|
||||||
"footer.userguide": {
|
"footer.userguide": {
|
||||||
"defaultMessage": "User Guide"
|
"defaultMessage": "User Guide"
|
||||||
},
|
},
|
||||||
|
|
|
@ -26,9 +26,6 @@
|
||||||
"footer.copyright": {
|
"footer.copyright": {
|
||||||
"defaultMessage": "حق چاپ © حق چاپ © {year} jc21.com"
|
"defaultMessage": "حق چاپ © حق چاپ © {year} jc21.com"
|
||||||
},
|
},
|
||||||
"footer.theme": {
|
|
||||||
"defaultMessage": "قالب توسط Tabler"
|
|
||||||
},
|
|
||||||
"footer.userguide": {
|
"footer.userguide": {
|
||||||
"defaultMessage": "راهنمای کاربر"
|
"defaultMessage": "راهنمای کاربر"
|
||||||
},
|
},
|
||||||
|
|
|
@ -126,15 +126,24 @@ function Login() {
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<Stack spacing={10}>
|
<Stack spacing={10}>
|
||||||
<Box textAlign={"end"}>
|
<Box textAlign={"end"}>
|
||||||
<Link color={"blue.400"}>Forgot password?</Link>
|
<Link color={"blue.400"}>
|
||||||
|
{intl.formatMessage({
|
||||||
|
id: "login.forgot",
|
||||||
|
defaultMessage: "Forgot password?",
|
||||||
|
})}
|
||||||
|
</Link>
|
||||||
</Box>
|
</Box>
|
||||||
<Button
|
<Button
|
||||||
type="submit"
|
type="submit"
|
||||||
loading={loading}
|
fontFamily={"heading"}
|
||||||
bg={"blue.400"}
|
mt={8}
|
||||||
|
w={"full"}
|
||||||
|
bgGradient="linear(to-r, red.400,pink.400)"
|
||||||
color={"white"}
|
color={"white"}
|
||||||
|
disabled={loading}
|
||||||
_hover={{
|
_hover={{
|
||||||
bg: "blue.500",
|
bgGradient: "linear(to-r, red.400,pink.400)",
|
||||||
|
boxShadow: "xl",
|
||||||
}}>
|
}}>
|
||||||
{intl.formatMessage({
|
{intl.formatMessage({
|
||||||
id: "login.login",
|
id: "login.login",
|
||||||
|
|
|
@ -1,19 +1,29 @@
|
||||||
import React, { useEffect, useRef, useState, ChangeEvent } from "react";
|
import React, { useEffect, useRef, useState, ChangeEvent } from "react";
|
||||||
|
|
||||||
|
import {
|
||||||
|
Box,
|
||||||
|
Flex,
|
||||||
|
Stack,
|
||||||
|
Heading,
|
||||||
|
Input,
|
||||||
|
Button,
|
||||||
|
useColorModeValue,
|
||||||
|
useToast,
|
||||||
|
} from "@chakra-ui/react";
|
||||||
import { createUser } from "api/npm";
|
import { createUser } from "api/npm";
|
||||||
import { Alert, Button } from "components";
|
|
||||||
import { LocalePicker } from "components";
|
import { LocalePicker } from "components";
|
||||||
import { useAuthState, useHealthState } from "context";
|
import { useAuthState, useHealthState } from "context";
|
||||||
import { intl } from "locale";
|
import { intl } from "locale";
|
||||||
|
|
||||||
import logo from "../../img/logo-text-vertical-grey.png";
|
import { ThemeSwitcher } from "../../components/ThemeSwitcher";
|
||||||
|
import logo from "../../img/logo-256.png";
|
||||||
|
|
||||||
function Setup() {
|
function Setup() {
|
||||||
|
const toast = useToast();
|
||||||
const nameRef = useRef(null);
|
const nameRef = useRef(null);
|
||||||
const { refreshHealth } = useHealthState();
|
const { refreshHealth } = useHealthState();
|
||||||
const { login } = useAuthState();
|
const { login } = useAuthState();
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [errorMessage, setErrorMessage] = useState("");
|
|
||||||
|
|
||||||
const [formData, setFormData] = useState({
|
const [formData, setFormData] = useState({
|
||||||
name: "",
|
name: "",
|
||||||
|
@ -23,9 +33,9 @@ function Setup() {
|
||||||
});
|
});
|
||||||
|
|
||||||
const onSubmit = async (e: React.FormEvent) => {
|
const onSubmit = async (e: React.FormEvent) => {
|
||||||
|
console.log("HERE");
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
setErrorMessage("");
|
|
||||||
|
|
||||||
const { password, ...payload } = {
|
const { password, ...payload } = {
|
||||||
...formData,
|
...formData,
|
||||||
|
@ -39,6 +49,17 @@ function Setup() {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const showErr = (msg: string) => {
|
||||||
|
toast({
|
||||||
|
title: "Signup Error",
|
||||||
|
description: msg,
|
||||||
|
status: "error",
|
||||||
|
position: "top",
|
||||||
|
duration: 3000,
|
||||||
|
isClosable: true,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await createUser({ payload });
|
const response = await createUser({ payload });
|
||||||
if (response && typeof response.id !== "undefined" && response.id) {
|
if (response && typeof response.id !== "undefined" && response.id) {
|
||||||
|
@ -49,14 +70,14 @@ function Setup() {
|
||||||
refreshHealth();
|
refreshHealth();
|
||||||
// window.location.reload();
|
// window.location.reload();
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
setErrorMessage(err.message);
|
showErr(err.message);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
setErrorMessage("Unable to create user!");
|
showErr("Unable to create user!");
|
||||||
}
|
}
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
setErrorMessage(err.message);
|
showErr(err.message);
|
||||||
}
|
}
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
};
|
};
|
||||||
|
@ -71,136 +92,117 @@ function Setup() {
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="page page-center">
|
<Flex
|
||||||
<div className="container-tight py-4">
|
minH={"100vh"}
|
||||||
<div className="text-center mb-4">
|
w={"100vw"}
|
||||||
<img src={logo} alt="Logo" />
|
flexDir={"column"}
|
||||||
</div>
|
bg={useColorModeValue("gray.50", "gray.800")}>
|
||||||
<form
|
<Stack h={10} m={4} justify={"end"} direction={"row"}>
|
||||||
className="card card-md"
|
<ThemeSwitcher />
|
||||||
method="post"
|
<LocalePicker className="text-right" />
|
||||||
autoComplete="off"
|
</Stack>
|
||||||
onSubmit={onSubmit}>
|
|
||||||
<div className="card-body">
|
<Flex align={"center"} justify={"center"} flex={"1"}>
|
||||||
<div className="row mb-4">
|
<Stack spacing={8} mx={"auto"} maxW={"md"} w={"full"} py={4} px={6}>
|
||||||
<div className="col">
|
<Box align={"center"}>
|
||||||
<h2 className="card-title">
|
<img src={logo} width={100} alt="Logo" />
|
||||||
|
</Box>
|
||||||
|
<Box
|
||||||
|
rounded={"lg"}
|
||||||
|
bg={useColorModeValue("white", "gray.700")}
|
||||||
|
boxShadow={"lg"}
|
||||||
|
p={8}>
|
||||||
|
<Stack spacing={4}>
|
||||||
|
<Heading
|
||||||
|
color={useColorModeValue("gray.800", "gray.300")}
|
||||||
|
lineHeight={1.1}
|
||||||
|
fontSize={{ base: "1xl", sm: "2xl", md: "3xl" }}>
|
||||||
|
{intl.formatMessage({
|
||||||
|
id: "setup.title",
|
||||||
|
defaultMessage: "Create your first Account",
|
||||||
|
})}
|
||||||
|
</Heading>
|
||||||
|
</Stack>
|
||||||
|
<Box mt={10}>
|
||||||
|
<form onSubmit={onSubmit}>
|
||||||
|
<Stack spacing={4}>
|
||||||
|
<Input
|
||||||
|
ref={nameRef}
|
||||||
|
onChange={onChange}
|
||||||
|
name="name"
|
||||||
|
value={formData.name}
|
||||||
|
disabled={loading}
|
||||||
|
placeholder={intl.formatMessage({
|
||||||
|
id: "user.name",
|
||||||
|
defaultMessage: "Name",
|
||||||
|
})}
|
||||||
|
maxLength={50}
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
<Input
|
||||||
|
onChange={onChange}
|
||||||
|
name="nickname"
|
||||||
|
value={formData.nickname}
|
||||||
|
disabled={loading}
|
||||||
|
placeholder={intl.formatMessage({
|
||||||
|
id: "user.nickname",
|
||||||
|
defaultMessage: "Nickname",
|
||||||
|
})}
|
||||||
|
maxLength={50}
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
<Input
|
||||||
|
type="email"
|
||||||
|
onChange={onChange}
|
||||||
|
name="email"
|
||||||
|
value={formData.email}
|
||||||
|
disabled={loading}
|
||||||
|
placeholder={intl.formatMessage({
|
||||||
|
id: "user.email",
|
||||||
|
defaultMessage: "Email",
|
||||||
|
})}
|
||||||
|
maxLength={150}
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
<Input
|
||||||
|
type="password"
|
||||||
|
onChange={onChange}
|
||||||
|
name="password"
|
||||||
|
value={formData.password}
|
||||||
|
disabled={loading}
|
||||||
|
placeholder={intl.formatMessage({
|
||||||
|
id: "user.password",
|
||||||
|
defaultMessage: "Password",
|
||||||
|
})}
|
||||||
|
minLength={8}
|
||||||
|
maxLength={100}
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
</Stack>
|
||||||
|
<Button
|
||||||
|
type="submit"
|
||||||
|
fontFamily={"heading"}
|
||||||
|
mt={8}
|
||||||
|
w={"full"}
|
||||||
|
bgGradient="linear(to-r, red.400,pink.400)"
|
||||||
|
color={"white"}
|
||||||
|
disabled={loading}
|
||||||
|
_hover={{
|
||||||
|
bgGradient: "linear(to-r, red.400,pink.400)",
|
||||||
|
boxShadow: "xl",
|
||||||
|
}}>
|
||||||
{intl.formatMessage({
|
{intl.formatMessage({
|
||||||
id: "setup.title",
|
id: "setup.create",
|
||||||
defaultMessage: "Create your first Account",
|
defaultMessage: "Create Account",
|
||||||
})}
|
})}
|
||||||
</h2>
|
</Button>
|
||||||
</div>
|
</form>
|
||||||
<div className="col col-md-2">
|
</Box>
|
||||||
<LocalePicker />
|
</Box>
|
||||||
</div>
|
</Stack>
|
||||||
</div>
|
</Flex>
|
||||||
|
<Box h={10} m={4} />
|
||||||
{errorMessage ? (
|
</Flex>
|
||||||
<Alert type="danger" className="text-center">
|
|
||||||
{errorMessage}
|
|
||||||
</Alert>
|
|
||||||
) : null}
|
|
||||||
|
|
||||||
<div className="mb-3">
|
|
||||||
<label className="form-label">
|
|
||||||
{intl.formatMessage({
|
|
||||||
id: "user.name",
|
|
||||||
defaultMessage: "Name",
|
|
||||||
})}
|
|
||||||
</label>
|
|
||||||
<input
|
|
||||||
ref={nameRef}
|
|
||||||
onChange={onChange}
|
|
||||||
className="form-control"
|
|
||||||
name="name"
|
|
||||||
value={formData.name}
|
|
||||||
disabled={loading}
|
|
||||||
placeholder={intl.formatMessage({
|
|
||||||
id: "user.name",
|
|
||||||
defaultMessage: "Name",
|
|
||||||
})}
|
|
||||||
required
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div className="mb-3">
|
|
||||||
<label className="form-label">
|
|
||||||
{intl.formatMessage({
|
|
||||||
id: "user.nickname",
|
|
||||||
defaultMessage: "Nickname",
|
|
||||||
})}
|
|
||||||
</label>
|
|
||||||
<input
|
|
||||||
onChange={onChange}
|
|
||||||
className="form-control"
|
|
||||||
name="nickname"
|
|
||||||
value={formData.nickname}
|
|
||||||
disabled={loading}
|
|
||||||
placeholder={intl.formatMessage({
|
|
||||||
id: "user.nickname",
|
|
||||||
defaultMessage: "Nickname",
|
|
||||||
})}
|
|
||||||
required
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div className="mb-3">
|
|
||||||
<label className="form-label">
|
|
||||||
{intl.formatMessage({
|
|
||||||
id: "user.email",
|
|
||||||
defaultMessage: "Email",
|
|
||||||
})}
|
|
||||||
</label>
|
|
||||||
<input
|
|
||||||
type="email"
|
|
||||||
onChange={onChange}
|
|
||||||
className="form-control"
|
|
||||||
name="email"
|
|
||||||
value={formData.email}
|
|
||||||
disabled={loading}
|
|
||||||
placeholder={intl.formatMessage({
|
|
||||||
id: "user.email",
|
|
||||||
defaultMessage: "Email",
|
|
||||||
})}
|
|
||||||
maxLength={150}
|
|
||||||
required
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div className="mb-3">
|
|
||||||
<label className="form-label">
|
|
||||||
{intl.formatMessage({
|
|
||||||
id: "user.password",
|
|
||||||
defaultMessage: "Password",
|
|
||||||
})}
|
|
||||||
</label>
|
|
||||||
<input
|
|
||||||
type="password"
|
|
||||||
onChange={onChange}
|
|
||||||
className="form-control"
|
|
||||||
name="password"
|
|
||||||
value={formData.password}
|
|
||||||
disabled={loading}
|
|
||||||
placeholder={intl.formatMessage({
|
|
||||||
id: "user.password",
|
|
||||||
defaultMessage: "Password",
|
|
||||||
})}
|
|
||||||
minLength={8}
|
|
||||||
maxLength={100}
|
|
||||||
autoComplete="off"
|
|
||||||
required
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div className="form-footer">
|
|
||||||
<Button color="cyan" loading={loading} className="w-100">
|
|
||||||
{intl.formatMessage({
|
|
||||||
id: "setup.create",
|
|
||||||
defaultMessage: "Create Account",
|
|
||||||
})}
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue