You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

214 line
8.3 KiB

  1. import React from "react";
  2. // @material-ui/core components
  3. import { makeStyles } from "@material-ui/core/styles";
  4. import InputAdornment from "@material-ui/core/InputAdornment";
  5. import Icon from "@material-ui/core/Icon";
  6. // @material-ui/icons
  7. import Email from "@material-ui/icons/Email";
  8. import People from "@material-ui/icons/People";
  9. // core components
  10. import GridContainer from "components/Grid/GridContainer.js";
  11. import GridItem from "components/Grid/GridItem.js";
  12. import Button from "components/CustomButtons/Button.js";
  13. import Card from "components/Card/Card.js";
  14. import CardBody from "components/Card/CardBody.js";
  15. import CardHeader from "components/Card/CardHeader.js";
  16. import CardFooter from "components/Card/CardFooter.js";
  17. import CustomInput from "components/CustomInput/CustomInput.js";
  18. import styles from "assets/jss/nextjs-material-kit/pages/loginPage.js";
  19. import image from "assets/img/bgtbg.jpg";
  20. import Collapse from "@material-ui/core/Collapse";
  21. import Alert from "@material-ui/lab/Alert";
  22. import IconButton from "@material-ui/core/IconButton";
  23. import CloseIcon from "@material-ui/icons/Close";
  24. import { useRouter } from "next/router";
  25. const useStyles = makeStyles(styles);
  26. export default function RegisterPage(props) {
  27. const [cardAnimaton, setCardAnimation] = React.useState("cardHidden");
  28. const [first_name] = React.useState("");
  29. const [last_name] = React.useState("");
  30. const [username] = React.useState("");
  31. const [email, setEmail] = React.useState("");
  32. const [pass, setPass] = React.useState("");
  33. const [open, setOpen] = React.useState(false);
  34. const [error, setError] = React.useState("");
  35. const router = useRouter();
  36. setTimeout(function () {
  37. setCardAnimation("");
  38. }, 700);
  39. const classes = useStyles();
  40. const { ...rest } = props;
  41. const submitHandler = async (event) => {
  42. event.preventDefault();
  43. const res = await fetch("../api/auth/login", {
  44. body: JSON.stringify({
  45. partner: "yamaha",
  46. first_name: first_name,
  47. last_name: last_name,
  48. username: username,
  49. email: email,
  50. pass: pass,
  51. }),
  52. headers: {
  53. "Content-Type": "application/json",
  54. },
  55. method: "POST",
  56. });
  57. // console.log("res", res.S);
  58. if (res.ok) {
  59. router.push("/yamaha/home");
  60. } else {
  61. setError(await res.text());
  62. setOpen(true);
  63. }
  64. };
  65. return (
  66. <div>
  67. <Collapse className={classes.collapsible} in={open}>
  68. <Alert
  69. severity="error"
  70. action={
  71. <IconButton
  72. aria-label="close"
  73. color="inherit"
  74. size="small"
  75. onClick={() => {
  76. setOpen(false);
  77. }}
  78. >
  79. <CloseIcon fontSize="inherit" />
  80. </IconButton>
  81. }
  82. >
  83. {error}
  84. </Alert>
  85. </Collapse>
  86. {/* <Header absolute color="info" rightLinks={<HeaderLinks />} {...rest} /> */}
  87. <div
  88. className={classes.pageHeader}
  89. style={{
  90. backgroundImage: "url(" + image + ")",
  91. backgroundSize: "cover",
  92. backgroundPosition: "top center",
  93. }}
  94. >
  95. <div className={classes.container}>
  96. <GridContainer justify="center">
  97. <GridItem xs={6}>
  98. <Card className={classes[cardAnimaton]}>
  99. <form onSubmit={submitHandler} className={classes.form}>
  100. <CardHeader color="info" className={classes.cardHeader}>
  101. <h4>Register</h4>
  102. </CardHeader>
  103. <p className={classes.divider}>Selamat Datang di Halaman Register Thamrin Brothers</p>
  104. <CardBody>
  105. <CustomInput
  106. labelText="Nama Depan"
  107. id="first_name"
  108. value={first_name}
  109. formControlProps={{
  110. fullWidth: true,
  111. }}
  112. inputProps={{
  113. type: "text",
  114. endAdornment: (
  115. <InputAdornment position="end">
  116. <People className={classes.inputIconsColor} />
  117. </InputAdornment>
  118. ),
  119. }}
  120. />
  121. <CustomInput
  122. labelText="Nama Belakang"
  123. id="last_name"
  124. value={last_name}
  125. formControlProps={{
  126. fullWidth: true,
  127. }}
  128. inputProps={{
  129. type: "text",
  130. endAdornment: (
  131. <InputAdornment position="end">
  132. <People className={classes.inputIconsColor} />
  133. </InputAdornment>
  134. ),
  135. }}
  136. />
  137. <CustomInput
  138. labelText="Username"
  139. id="username"
  140. value={username}
  141. formControlProps={{
  142. fullWidth: true,
  143. }}
  144. inputProps={{
  145. type: "text",
  146. endAdornment: (
  147. <InputAdornment position="end">
  148. <People className={classes.inputIconsColor} />
  149. </InputAdornment>
  150. ),
  151. }}
  152. />
  153. <CustomInput
  154. labelText="Email..."
  155. id="email"
  156. value={email}
  157. formControlProps={{
  158. fullWidth: true,
  159. }}
  160. inputProps={{
  161. type: "email",
  162. onChange: (event) => setEmail(event.target.value),
  163. endAdornment: (
  164. <InputAdornment position="end">
  165. <Email className={classes.inputIconsColor} />
  166. </InputAdornment>
  167. ),
  168. }}
  169. />
  170. <CustomInput
  171. labelText="Password"
  172. id="pass"
  173. value={pass}
  174. formControlProps={{
  175. fullWidth: true,
  176. }}
  177. inputProps={{
  178. onChange: (event) => setPass(event.target.value),
  179. type: "password",
  180. endAdornment: (
  181. <InputAdornment position="end">
  182. <Icon className={classes.inputIconsColor}>
  183. lock_outline
  184. </Icon>
  185. </InputAdornment>
  186. ),
  187. autoComplete: "off",
  188. }}
  189. />
  190. </CardBody>
  191. <div align="center">
  192. <a href="/yamaha/login">Sudah Punya Akun ? Silahkan Login</a>
  193. </div><br></br>
  194. <CardFooter className={classes.cardFooter}>
  195. <Button type="submit" color="info" size="lg">
  196. Register
  197. </Button>
  198. </CardFooter>
  199. </form>
  200. </Card>
  201. </GridItem>
  202. </GridContainer>
  203. </div>
  204. </div>
  205. </div>
  206. );
  207. }