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.
 
 

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