Skip to content

Commit

Permalink
consume APIs for assigned tasks and remove all console log from codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
asoluka committed May 23, 2023
1 parent db011b7 commit b2abeca
Show file tree
Hide file tree
Showing 35 changed files with 1,219 additions and 1,458 deletions.
110 changes: 59 additions & 51 deletions frontend/mms-Admin/components/AddMentor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@ import React, { useState } from "react";
import { Modal } from "antd";
import styles from "./componentStyles/splashscreen.module.css";
import { CustomButton, CustomInput } from "./formInputs/CustomInput";
import toast from 'react-hot-toast';
import toast from "react-hot-toast";
import { inviteMentor } from "pages/api/user";
import AddMentorSuccess from "./AddMentorSuccess"
import AddMentorSuccess from "./AddMentorSuccess";

function AddMentor({
message,
isOpen,
setIsOpen,
}) {
function AddMentor({ message, isOpen, setIsOpen }) {
const [formData, setFormData] = useState({
firstName: '',
lastName: '',
email: '',
roleId: 2
firstName: "",
lastName: "",
email: "",
roleId: 2,
});
const [open, setOpen] = useState(false);
const [loading, setLoading] = useState(false);
Expand All @@ -28,38 +24,43 @@ function AddMentor({
setOpen(true);
};


const validateForm = () => {
if (formData.firstName.length < 4 || formData.email.length < 4 || formData.lastName.length < 4 ) {
window.alert('First name, Last name and email must be at least 4 characters long.');
if (
formData.firstName.length < 4 ||
formData.email.length < 4 ||
formData.lastName.length < 4
) {
window.alert(
"First name, Last name and email must be at least 4 characters long.",
);
return false;
}
return true;
};

const InviteMentor = async () => {
setLoading(true);
try {
const isFormValid = validateForm();
if (!isFormValid) return;

const response = await inviteMentor(formData);
console.log(response)

if (response.status === 202) {
toast.success(response?.data?.message);
handleInvite()
handleInvite();
setLoading(false);
}
} catch (e) {
console.error(e);
toast.error(e);
}
};
const handleInviteMentor = event => {
const handleInviteMentor = (event) => {
const { name, value } = event.target;
setFormData(prevState => ({
setFormData((prevState) => ({
...prevState,
[name]: value
[name]: value,
}));
};

Expand All @@ -78,41 +79,48 @@ function AddMentor({
<p className={styles.modal_text}>{message}</p>
</div>
<form>
<div className={styles.invite_input}>
<div className={styles.invite_input_name}>
<div className={styles.invite_input_name_first}>
<CustomInput
placeholder="Enter First Name"
name="firstName"
required
value={formData.firstName}
onChange={handleInviteMentor}
/>
<div className={styles.invite_input}>
<div className={styles.invite_input_name}>
<div className={styles.invite_input_name_first}>
<CustomInput
placeholder="Enter First Name"
name="firstName"
required
value={formData.firstName}
onChange={handleInviteMentor}
/>
</div>
<div>
<CustomInput
placeholder="Enter Last Name"
name="lastName"
required
value={formData.lastName}
onChange={handleInviteMentor}
/>
</div>
</div>
<div>
<CustomInput
placeholder="Enter Last Name"
name="lastName"
<CustomInput
size="large"
placeholder="Enter Email Address"
name="email"
type="email"
required
value={formData.lastName}
value={formData.email}
onChange={handleInviteMentor}
/>
</div>
</div>
<CustomInput
size="large"
placeholder="Enter Email Address"
name="email"
type="email"
required
value={formData.email}
onChange={handleInviteMentor}
/>
</div>
<div className={styles.invite_input_name_btn}>
<CustomButton onClick={handleClose} className={styles.modal_b1}>Cancel</CustomButton>
<CustomButton onClick={InviteMentor} disabled={loading}className={styles.modal_b2}>Send</CustomButton>
</div>
<div className={styles.invite_input_name_btn}>
<CustomButton onClick={handleClose} className={styles.modal_b1}>
Cancel
</CustomButton>
<CustomButton
onClick={InviteMentor}
disabled={loading}
className={styles.modal_b2}>
Send
</CustomButton>
</div>
</form>
</div>
{open && (
Expand Down
Loading

0 comments on commit b2abeca

Please sign in to comment.