Skip to content

Commit

Permalink
Add team member fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
BHS-Harish committed Aug 9, 2024
1 parent 06c0210 commit 8905100
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 29 deletions.
21 changes: 10 additions & 11 deletions frontend/src/pages/Admin/Components/AddTeamMember/AddTeamMember.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ export function AddTeamMember() {
setFormErrors(errors);
};


const onSubmit = async (e) => {
e.preventDefault();
const errors = validate();
Expand Down Expand Up @@ -135,15 +134,15 @@ export function AddTeamMember() {
console.log(errors);
} else {
//Call the Server
const form = new FormData();
form.append("fullName", formdata?.fullName);
form.append("description", formdata?.description);
form.append("linkedinUrl", formdata?.linkedin);
form.append("githubUrl", formdata.github);
form.append("twitterUrl", formdata.twitter);
form.append("teams", selectTeam);
form.append("image", pic);
await postTeamMember(form,setToast,toast);
const form = new Object();
form["fullName"] = formdata?.fullName;
form["description"] = formdata?.description;
form["linkedinUrl"] = formdata?.linkedin;
form["githubUrl"] = formdata.github;
form["twitterUrl"] = formdata.twitter;
form["teams"] = selectTeam;
form["image"] = pic;
await postTeamMember(form, setToast, toast);
const temp = {
fullName: "",
description: "",
Expand Down Expand Up @@ -328,7 +327,7 @@ export function AddTeamMember() {
</div>
</div>
</div>

{toast.toastStatus && (
<SimpleToast
open={toast.toastStatus}
Expand Down
44 changes: 26 additions & 18 deletions frontend/src/service/About.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { DELETE_FAIL, DELETE_SUCCESS, GET_FAIL, GET_SUCCESS, POST_FAIL, POST_SUCCUSS } from "../common/constants";
import {
DELETE_FAIL,
DELETE_SUCCESS,
GET_FAIL,
GET_SUCCESS,
POST_FAIL,
POST_SUCCUSS,
} from "../common/constants";
import { END_POINT } from "../config/api";

const getTeamMembers = async (setToast, toast) => {
Expand All @@ -12,22 +19,22 @@ const getTeamMembers = async (setToast, toast) => {
});
const data = await response.json();
const _data = data.map((item) => {
return {
...item,
teams: item.teams[0].split(","),
};
});
let _image = [];
await _data?.map((item) => {
let formattedPath = item.image?.replace(/\\/g, "/");
if (formattedPath?.startsWith("uploads/")) {
formattedPath = formattedPath.replace("uploads/", "");
if (formattedPath) {
formattedPath = `${END_POINT}/${formattedPath}`;
}
return {
...item,
teams: item.teams,
};
});
let _image = [];
await _data?.map((item) => {
let formattedPath = item.image?.replace(/\\/g, "/");
if (formattedPath?.startsWith("uploads/")) {
formattedPath = formattedPath.replace("uploads/", "");
if (formattedPath) {
formattedPath = `${END_POINT}/${formattedPath}`;
}
_image.push({ image: formattedPath, id: item._id });
});
}
_image.push({ image: formattedPath, id: item._id });
});

setToast({
...toast,
Expand All @@ -47,12 +54,13 @@ const getTeamMembers = async (setToast, toast) => {
}
};

const postTeamMember = async (data,setToast,toast) => {
const postTeamMember = async (data, setToast, toast) => {
try {
const response = await fetch(`${END_POINT}/teamMember/addTeamMember`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${localStorage.getItem("token")}`,
},
body: JSON.stringify(data),
});
Expand Down Expand Up @@ -105,4 +113,4 @@ const deleteTeamMember = async (id, setToast, toast) => {
}
};

export { getTeamMembers, postTeamMember, deleteTeamMember};
export { getTeamMembers, postTeamMember, deleteTeamMember };

0 comments on commit 8905100

Please sign in to comment.