import React, { useContext, useReducer, useState } from "react"; import { Helmet } from "react-helmet-async"; import { Store } from "../Store"; import Form from "react-bootstrap/Form"; import Button from "react-bootstrap/Button"; import { toast } from "react-toastify"; import { getError } from "../components/utils"; import axios from "axios"; const reducer = (state, action) => { switch (action.type) { case "UPDATE_REQUEST": return { ...state, loadingUpdate: true }; case "UPDATE_SUCCSS": return { ...state, loadingUpdate: false }; case "UPDATE_FAIL": return { ...state, loadingUpdate: false }; default: return state; } }; function ProfileScreen() { const { state, dispatch: ctxDispatch } = useContext(Store); const { userInfo } = state; const [name, setName] = useState(userInfo.name); const [contact, setContact] = useState(userInfo.contact); const [email, setEmail] = useState(userInfo.email); const [password, setPassword] = useState(""); const [confirmPassword, setConfirmPassword] = useState(""); const [{ loadingUpdate }, dispatch] = useReducer(reducer, { loadingUpdate: false, }); const submitHandler = async (e) => { e.preventDefault(); try { const { data } = await axios.put( "/api/users/profile", { name, contact, email, password, }, { headers: { Authorization: `Bearer ${userInfo.token}` }, } ); dispatch({ type: "UPDATE_SUCCESS" }); ctxDispatch({ type: "USER_SIGNIN", payload: data }); localStorage.setItem("userInfo", JSON.stringify(data)); toast.success("Успешно ажурирање"); } catch (err) { dispatch({ type: "FETCH_FAIL" }); toast.error(getError(err)); } }; return (
Мој профил

Моите податоци

Име и Презиме setName(e.target.value)} /> Телефон setContact(e.target.value)} /> Email setEmail(e.target.value)} /> Лозинка setPassword(e.target.value)} /> Потврди Лозинка setConfirmPassword(e.target.value)} />
); } export default ProfileScreen;