| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- import { NextPage } from "next/types";
- import { useEffect } from "react";
- import Layout from "../components/Layout";
- import { useAuth } from "../context/UserContext";
- import useForm from "../hooks/useForm";
- import api from "../utils/api";
- const Settings: NextPage = () => {
- const { updateUser, user } = useAuth();
- const { error, submitHandler, success } = useForm(api.updateUser);
- useEffect(() => {
- if (success) {
- updateUser(success.result);
- }
- }, [success, updateUser]);
- return user ? (
- <Layout>
- <form className="form" onSubmit={submitHandler}>
- <div className="form-group">
- <label htmlFor="name" className="form-label">
- Name
- </label>
- <input
- type="text"
- name="name"
- id="name"
- className="form-input"
- defaultValue={user.name}
- required
- />
- </div>
- <div className="form-group">
- <label htmlFor="email" className="form-label">
- Email
- </label>
- <input
- type="email"
- name="email"
- id="email"
- className="form-input"
- defaultValue={user.email}
- required
- />
- </div>
- <div className="form-group">
- <label htmlFor="password" className="form-label">
- Password
- </label>
- <input
- type="password"
- id="password"
- name="password"
- className="form-input"
- defaultValue={user.password}
- minLength={6}
- required
- />
- </div>
- <div className="form-group">
- <label htmlFor="team" className="form-label">
- Team
- </label>
- <select
- className="form-input"
- id="team"
- name="team"
- defaultValue={user.team}
- required
- >
- <option value="Admins">Admins</option>
- <option value="Users">Users</option>
- <option value="Viewers">Viewers</option>
- </select>
- </div>
- <input type="hidden" id="id" name="id" value={user.id} />
- <button type="submit" className="form-button">
- Save
- </button>
- {error && !success && (
- <div role="alert" className="form-alert-msg">
- {error.message}
- </div>
- )}
- {success && (
- <div role="alert" className="form-success-msg">
- Profile updated correctly
- </div>
- )}
- </form>
- </Layout>
- ) : null;
- };
- export default Settings;
|