settings.tsx 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import { NextPage } from "next/types";
  2. import { useEffect } from "react";
  3. import Layout from "../components/Layout";
  4. import useForm from "../hooks/useForm";
  5. import api from "../utils/api";
  6. const Settings: NextPage = () => {
  7. const user = {
  8. id: 4,
  9. name: "Monkey",
  10. email: "monkey@gmail.com",
  11. password: "123456",
  12. team: "Admins",
  13. };
  14. const { error, submitHandler, success } = useForm(api.updateUser);
  15. useEffect(() => {
  16. if (success) {
  17. console.log(success);
  18. }
  19. }, [success]);
  20. return (
  21. <Layout>
  22. <form className="form" onSubmit={submitHandler}>
  23. <div className="form-group">
  24. <label htmlFor="name" className="form-label">
  25. Name
  26. </label>
  27. <input
  28. type="text"
  29. name="name"
  30. id="name"
  31. className="form-input"
  32. defaultValue={user.name}
  33. />
  34. </div>
  35. <div className="form-group">
  36. <label htmlFor="email" className="form-label">
  37. Email
  38. </label>
  39. <input
  40. type="email"
  41. name="email"
  42. id="email"
  43. className="form-input"
  44. defaultValue={user.email}
  45. />
  46. </div>
  47. <div className="form-group">
  48. <label htmlFor="password" className="form-label">
  49. Password
  50. </label>
  51. <input
  52. type="password"
  53. id="password"
  54. name="password"
  55. className="form-input"
  56. defaultValue={user.password}
  57. minLength={6}
  58. />
  59. </div>
  60. <div className="form-group">
  61. <label htmlFor="team" className="form-label">
  62. Team
  63. </label>
  64. <select
  65. className="form-input"
  66. id="team"
  67. name="team"
  68. defaultValue={user.team}
  69. >
  70. <option value="Admins">Admins</option>
  71. <option value="Users">Users</option>
  72. <option value="Viewers">Viewers</option>
  73. </select>
  74. </div>
  75. <input type="hidden" id="id" name="id" value={user.id} />
  76. <button type="submit" className="form-button">
  77. Save
  78. </button>
  79. {error && (
  80. <div role="alert" className="form-alert-msg">
  81. {error.message}
  82. </div>
  83. )}
  84. </form>
  85. </Layout>
  86. );
  87. };
  88. export default Settings;