Skip to content

Commit

Permalink
Fix prmise handling in adding user
Browse files Browse the repository at this point in the history
  • Loading branch information
qbentil committed Jul 13, 2023
1 parent 9eadf03 commit c219956
Showing 1 changed file with 28 additions and 29 deletions.
57 changes: 28 additions & 29 deletions admin/users/new/index.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
import { SketchPicker } from "react-color";
import { FaUserCog, FaUserTag } from "react-icons/fa";
import {
MdOutlineAddCircleOutline,
MdOutlineAlternateEmail,
} from "react-icons/md";
import { SiAboutdotme } from "react-icons/si";
import { Navbar, Sidenav } from "../../../components/Admin";
import React, { useState } from "react";
import Button from "../../../components/Button/";
import Head from "next/head";
import ImageUploader from "../../../components/ImageUploader";
import { removeImage, uploadImage } from "../../../firebase";
import { useStateValue } from "../../../context/StateProvider";
import { toast } from "react-toastify";

import { ADD_ADMIN } from "../../../util/admins";
import { BiLoaderCircle } from "react-icons/bi";
import Button from "../../../components/Button/";
import { CgNametag } from "react-icons/cg";
import { FaUserCog, FaUserTag } from "react-icons/fa";
import Usertype from "../../../components/Selectors/usertype";
import { ADD_ADMIN } from "../../../util/admins";
import Head from "next/head";
import ImageUploader from "../../../components/ImageUploader";
import { SiAboutdotme } from "react-icons/si";
import { SketchPicker } from "react-color";
import { User } from "../../../types";
import Usertype from "../../../components/Selectors/usertype";
import { toast } from "react-toastify";
import { useStateValue } from "../../../context/StateProvider";

const NewCategory = () => {
const [{ user }, dispatch] = useStateValue();
Expand All @@ -27,7 +28,7 @@ const NewCategory = () => {
const [about, setAbout] = useState("");
const [name, setName] = useState("");
const [email, setEmail] = useState("");
const [role, setRole] = useState({value: 'writer', label: 'Writer'});
const [role, setRole] = useState({ value: 'writer', label: 'Writer' });
const [loading, setLoading] = useState(false);

const clearFields = () => {
Expand All @@ -37,7 +38,7 @@ const NewCategory = () => {
setAbout("");
setImage("");
setImageURI("");
setRole({value: 'writer', label: 'Writer'});
setRole({ value: 'writer', label: 'Writer' });
};

//Add category to database here
Expand All @@ -50,33 +51,31 @@ const NewCategory = () => {
username,
about,
avatar: '',
role : role.value,
role: role.value,
};
console.log(userData)
// console.log(userData)
if (!name || !email || !username || !image || !role.value) {
toast.error("Please fill in all fields");
return;
}
// upload user photo
toast.promise(uploadImage(imageURI, "users", async (url: string) => {
uploadImage(imageURI, "users", async (url: string) => {
userData.avatar = url;
// save to database
await ADD_ADMIN(user?.access_token, userData, (data:User) => {
dispatch({
type: "ADD_USER",
user: data,
})
toast.promise(ADD_ADMIN(user?.access_token, userData, (data: User) => {
dispatch({
type: "ADD_USER",
user: data,
})
toast.success("User added successfully🎉");
setLoading(false);
clearFields();
}), {
pending: "Adding user...",
}, {
toastId: "addUser",
});
toast.success("User added successfully🎉");
setLoading(false);
clearFields();
}),{
pending: "Adding user...",
}, {
toastId: "addUser",
})
// await add user
setLoading(false);
};

return (
Expand Down

1 comment on commit c219956

@vercel
Copy link

@vercel vercel bot commented on c219956 Jul 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

bentility – ./

bentility-qbentil.vercel.app
bentility.vercel.app
bentility-git-master-qbentil.vercel.app

Please sign in to comment.