settings.tsx 2.3 KB

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