diff --git a/src/pages/EditPortfolio/EducationTab.jsx b/src/pages/EditPortfolio/EducationTab.jsx index a40c194..ed20031 100644 --- a/src/pages/EditPortfolio/EducationTab.jsx +++ b/src/pages/EditPortfolio/EducationTab.jsx @@ -14,12 +14,13 @@ const checkGPA = gpa => typeof(gpa) === "number" && gpa >= 0.00 && gpa <= 5.00 */ const AddEducationModal = ({ toggle, isOpen }) => { const initialForm = { - school_name: "", - school_type: "", - graduation_reward: "", + schoolName: "", + schoolType: "", + schoolURL: "", + rewardType: "", major: "", - logo_id: "", - graduation_date: new Date(), + imageId: "", + graduationDate: new Date(), gpa: 0.00 } @@ -50,15 +51,15 @@ const AddEducationModal = ({ toggle, isOpen }) => { return var formData = new FormData() - formData.append("logo", image) + formData.append("file", image) setState({ ...state, loading: true }) - request("/portfolio/education/upload-image", formData, "POST", true, "multipart/form-data") + request("/portfolio/education/logo", formData, "POST", true, "multipart/form-data") .then(res => { setState({ ...state, loading: false, data: res.data }) - updateField("logo_id", res.data.id) + updateField("imageId", res.data.id) }) .catch(err => setState({ ...state, loading: false, error: err })) } @@ -124,15 +125,19 @@ const AddEducationModal = ({ toggle, isOpen }) => {
- updateField("school_name", e.target.value)} /> + updateField("schoolName", e.target.value)} /> - updateField("school_type", e.target.value)} /> + updateField("schoolType", e.target.value)} /> + + + + updateField("schoolURL", e.target.value)} /> - updateField("graduation_reward", e.target.value)} /> + updateField("rewardType", e.target.value)} /> E.g. Diploma, Bachelor's Degree @@ -147,7 +152,7 @@ const AddEducationModal = ({ toggle, isOpen }) => { - updateField("graduation_date", e.target.value)} /> + updateField("graduationDate", e.target.value)} /> @@ -254,7 +259,7 @@ const EditEducationModal = ({ toggle, isOpen, id }) => { setState({ loading: true, data: null, error: null }) - request(`/portfolio/education`, { id }, "DELETE", true) + request(`/portfolio/education/${id}`, null, "DELETE", true) .then(res => { setState({ loading: false, data: res.data }) @@ -345,9 +350,9 @@ const EditEducationModal = ({ toggle, isOpen, id }) => { } const EducationCard = ({ data, toggleEditModal }) => { - const { id, school_name, school_logo, school_type, graduation_date, graduation_reward, major, gpa } = data + const { id, schoolName, logoURL, schoolType, graduationDate, rewardType, major, gpa } = data - const gradDate = new Date(graduation_date), hasGraduated = gradDate < new Date() + const gradDate = new Date(graduationDate), hasGraduated = gradDate < new Date() const dateToStr = date => `${date.getMonth()+1}/${date.getFullYear()}` @@ -365,17 +370,17 @@ const EducationCard = ({ data, toggleEditModal }) => { - school-logo-2 + school-logo-2 -

{school_name}

-

{school_type}

+

{schoolName}

+

{schoolType}

- {`${majorAndRewardProcess(graduation_reward, major)}`} + {`${majorAndRewardProcess(rewardType, major)}`}
{`${gpa} GPA`}
@@ -441,7 +446,7 @@ export const EducationTab = props => { .catch(err => setState({ ...state, loading: false, error: err })) } - //console.log(state) + // console.log(state) return ( <> @@ -459,10 +464,10 @@ export const EducationTab = props => { {!state.loading && state.data ? <> - {state.data.education.length === 0 && + {state.data.length === 0 &&

No education data found...

} - {state.data.education.map((obj, i) => ( + {state.data.map((obj, i) => ( 1 ? " mt-3" : ""}`}> diff --git a/src/pages/EditPortfolio/ImageTab.jsx b/src/pages/EditPortfolio/ImageTab.jsx index 1f9c407..080b864 100644 --- a/src/pages/EditPortfolio/ImageTab.jsx +++ b/src/pages/EditPortfolio/ImageTab.jsx @@ -48,7 +48,7 @@ const ImageDeleteModal = ({ isOpen, toggle, images }) => { setState({ ...state, loading: true }) - request(`/portfolio/image`, { id }, "DELETE", true) + request(`/portfolio/image/${id}`, null, "DELETE", true) .then(res => { setState({ ...state, loading: false, data: res.data }) @@ -70,14 +70,14 @@ const ImageDeleteModal = ({ isOpen, toggle, images }) => {
- {!selectedImage ? "Select Image" : selectedImage.file_name} + {!selectedImage ? "Select Image" : selectedImage.fileName} {images.length === 0 && N/A } {images.length > 0 && images.map((img, i) => ( - updateSelectedImage(e, img)}>{img.file_name} + updateSelectedImage(e, img)}>{img.fileName} ))} @@ -101,7 +101,7 @@ const ImageDeleteModal = ({ isOpen, toggle, images }) => { } const ImageCard = ({ image }) => { - const { id, url, file_name } = image + const { id, url, fileName } = image return ( @@ -113,7 +113,7 @@ const ImageCard = ({ image }) => { -

{file_name}

+

{fileName}

{id}

{url}

@@ -160,11 +160,11 @@ export const ImageTab = props => { toggle() } - //console.log(state) + // console.log(state) return ( <> - toggle(refresh)} images={state.data ? state.data.images : []} /> + toggle(refresh)} images={state.data ? state.data : []} /> @@ -178,10 +178,10 @@ export const ImageTab = props => { {!state.loading && state.data ? <> - {state.data.images.length == 0 && + {state.data.length == 0 &&

No images found...

} - {state.data.images.map((obj, i) => ( + {state.data.map((obj, i) => ( 2 ? " mt-3" : ""}`}> diff --git a/src/pages/EditPortfolio/PositionTab.jsx b/src/pages/EditPortfolio/PositionTab.jsx index dc87e0e..cf1ec25 100644 --- a/src/pages/EditPortfolio/PositionTab.jsx +++ b/src/pages/EditPortfolio/PositionTab.jsx @@ -12,15 +12,22 @@ import { request } from "../../api" const NO_IMG_URL = "https://upload.wikimedia.org/wikipedia/commons/a/ac/No_image_available.svg" +const processServerDate = date => { + if (!date) return date; + + var jsDate = new Date(date); + return jsDate.toISOString().split('T')[0]; +} + const AddPositionModal = ({ isOpen, toggle }) => { const initialForm = { - job_title: "", - company_name: "", - company_url: "", + jobTitle: "", + companyName: "", + companyURL: "", description: "", - start_date: "", - end_date: "", - logo_id: "" + startDate: "", + endDate: "", + imageId: "" } const [form, setForm] = useState(initialForm) @@ -51,39 +58,48 @@ const AddPositionModal = ({ isOpen, toggle }) => { return var formData = new FormData() - formData.append("logo", image) + formData.append("file", image) setState({ ...state, loading: true }) - request("/portfolio/position/upload-image", formData, "POST", true, "multipart/form-data") + request("/portfolio/position/logo", formData, "POST", true, "multipart/form-data") .then(res => { setState({ ...state, loading: false, data: res.data }) - updateField("logo_id", res.data.id) + updateField("imageId", res.data.id) }) .catch(err => setState({ ...state, loading: false, error: err })) } const validateForm = () => { - let valid = true + let valid = true, invalidKeys = [], updatedForm = { ...form } Object.keys(form).forEach(key => { - if(typeof(form[key]) === "string" && (key !== "company_url") && form[key].length === 0) + if(typeof(form[key]) === "string" && (key !== "companyURL" && key !== "endDate") && form[key].length === 0) + { valid = false + invalidKeys.push(key); + } }) - return valid + if (invalidKeys.length > 0) console.log(`Invalid keys: ${invalidKeys.join(', ')}`) + + return { valid, updatedForm } } const submitData = e => { e.preventDefault() - if(!validateForm()) + var { valid, formToSend } = validateForm() + + if(!valid) return setState({ ...state, loading: true, data: null, error: null }) - request("/portfolio/position", form, "POST", true) + var endDate = form.endDate !== "" ? form.endDate : undefined + + request("/portfolio/position", { ...form, endDate }, "POST", true) .then(res => { setState({ ...state, loading: false, data: res.data }) @@ -119,7 +135,7 @@ const AddPositionModal = ({ isOpen, toggle }) => {

Upload Logo

updateImage(e)} /> - Image Identifier: {form.logo_id ? form.logo_id : "N/A"} + Image Identifier: {form.imageId ? form.imageId : "N/A"}
@@ -129,24 +145,24 @@ const AddPositionModal = ({ isOpen, toggle }) => {
- updateField("job_title", e.target.value)} /> + updateField("jobTitle", e.target.value)} /> - updateField("company_name", e.target.value)} /> + updateField("companyName", e.target.value)} /> - updateField("company_url", e.target.value)} /> + updateField("companyURL", e.target.value)} /> If applicable - updateField("start_date", e.target.value)} /> + updateField("startDate", e.target.value)} /> - updateField("end_date", e.target.value)} /> + updateField("endDate", e.target.value)} /> @@ -165,13 +181,13 @@ const AddPositionModal = ({ isOpen, toggle }) => { const EditPositionModal = ({ isOpen, toggle, id }) => { const initialForm = { - job_title: "", - company_name: "", - company_url: "", + jobTitle: "", + companyName: "", + companyURL: "", description: "", - start_date: "", - end_date: "", - logo_id: "" + startDate: "", + endDate: "", + imageId: "" } const [form, setForm] = useState(initialForm) @@ -185,7 +201,7 @@ const EditPositionModal = ({ isOpen, toggle, id }) => { const [loaded, setLoaded] = useState({ isLoaded: false, original_data: null, - logo_url: "", + logoURL: "", error: null }) @@ -208,46 +224,47 @@ const EditPositionModal = ({ isOpen, toggle, id }) => { return var formData = new FormData() - formData.append("logo", image) + formData.append("file", image) setState({ ...state, loading: true }) - request("/portfolio/position/upload-image", formData, "POST", true, "multipart/form-data") + request("/portfolio/position/logo", formData, "POST", true, "multipart/form-data") .then(res => { setState({ ...state, loading: false, data: res.data }) - updateField("logo_id", res.data.id) + updateField("imageId", res.data.id) }) .catch(err => setState({ ...state, loading: false, error: err })) } - const validateFormAndCondense = () => { - let valid = true, condensedForm = {} - - const excludedKeys = [ "company_url", "logo_id", "end_date" ] + const validateForm = () => { + let valid = true, invalidKeys = [], updatedForm = { ...form } Object.keys(form).forEach(key => { - if(typeof(form[key]) === "string" && !excludedKeys.includes(key) && form[key].length === 0) { + if(typeof(form[key]) === "string" && (key !== "companyURL" && key !== "endDate") && form[key].length === 0) + { valid = false - } else if(typeof(form[key]) === "string" && form[key].length > 0 && form[key] !== loaded.original_data[key]) - condensedForm[key] = form[key] + invalidKeys.push(key); + } }) - console.log(condensedForm, valid) + if (invalidKeys.length > 0) console.log(`Invalid keys: ${invalidKeys.join(', ')}`) - return { condensedForm, isValid: valid } + return { valid, updatedForm } } const submitData = e => { e.preventDefault() - const { condensedForm, isValid } = validateFormAndCondense() + const { valid, _ } = validateForm() - if(!isValid) return + if(!valid) return setState({ loading: true, data: null, error: null }) - request(`/portfolio/position/${id}`, condensedForm, "PATCH", true) + var endDate = form.endDate !== "" ? form.endDate : undefined + + request(`/portfolio/position/${id}`, { ...form, endDate }, "PATCH", true) .then(res => { setState({ loading: false, data: res.data }) @@ -261,7 +278,7 @@ const EditPositionModal = ({ isOpen, toggle, id }) => { setState({ loading: true, data: null, error: null }) - request(`/portfolio/position`, { id }, "DELETE", true) + request(`/portfolio/position/${id}`, null, "DELETE", true) .then(res => { setState({ loading: false, data: res.data }) @@ -287,7 +304,7 @@ const EditPositionModal = ({ isOpen, toggle, id }) => { if(res.data.description) setDescription(res.data.description) - setLoaded({ isLoaded: true, logo_url: res.data.logo_url, original_data: res.data }) + setLoaded({ isLoaded: true, logoURL: res.data.logoURL, original_data: res.data }) }) .catch(err => setLoaded({ error: err })) } @@ -304,7 +321,7 @@ const EditPositionModal = ({ isOpen, toggle, id }) => { setLoaded({ isLoaded: false, original_data: null, - logo_url: "", + logoURL: "", error: null }) @@ -319,13 +336,13 @@ const EditPositionModal = ({ isOpen, toggle, id }) => { - +

Upload Logo

updateImage(e)} /> - Image Identifier: {form.logo_id ? form.logo_id : "N/A"} + Image Identifier: {form.imageId ? form.imageId : "N/A"}
@@ -335,24 +352,24 @@ const EditPositionModal = ({ isOpen, toggle, id }) => {
- updateField("job_title", e.target.value)} /> + updateField("jobTitle", e.target.value)} /> - updateField("company_name", e.target.value)} /> + updateField("companyName", e.target.value)} /> - updateField("company_url", e.target.value)} /> + updateField("companyURL", e.target.value)} /> If applicable - updateField("start_date", e.target.value)} /> + updateField("startDate", e.target.value)} /> - updateField("end_date", e.target.value)} /> + updateField("endDate", e.target.value)} /> @@ -371,7 +388,7 @@ const EditPositionModal = ({ isOpen, toggle, id }) => { } const PositionCard = ({ position, toggleModal }) => { - const { id, company_name, description, company_url, start_date, end_date, logo_url } = position + const { id, companyName, description, companyURL, startDate, endDate, logoURL } = position const convertDateToString = dateStr => { if(!dateStr) return "Present" @@ -386,16 +403,16 @@ const PositionCard = ({ position, toggleModal }) => { - + -

{company_url ? {company_name} : <>{company_name}}

+

{companyURL ? {companyName} : <>{companyName}}

-

{convertDateToString(start_date)} - {convertDateToString(end_date)}

+

{convertDateToString(startDate)} - {convertDateToString(endDate)}

Description

@@ -473,10 +490,10 @@ export const PositionTab = props => { {!state.loading && state.data ? <> - {state.data.positions.length == 0 && + {state.data.length == 0 &&

No position data found...

} - {state.data.positions.map((obj, i) => ( + {state.data.map((obj, i) => ( 1 ? " mt-3" : ""}`}> diff --git a/src/pages/EditPortfolio/ProjectTab.jsx b/src/pages/EditPortfolio/ProjectTab.jsx index 3fb910c..ecd4705 100644 --- a/src/pages/EditPortfolio/ProjectTab.jsx +++ b/src/pages/EditPortfolio/ProjectTab.jsx @@ -17,8 +17,8 @@ const AddProjectModal = ({ isOpen, toggle }) => { name: "", description: "", url: "", - repo_url: "", - logo_id: "", + repoURL: "", + imageId: "", images: [], tools: [] }) @@ -101,18 +101,16 @@ const AddProjectModal = ({ isOpen, toggle }) => { return var formData = new FormData() - formData.append("image", image.data) - if(image.isLogo) - formData.append("is_logo", "true") + formData.append("file", image.data) setState({ loading: true }) - request("/portfolio/project/upload-image", formData, "POST", true, "multipart/form-data") + request(`/portfolio/project/upload-${image.isLogo ? "logo" : "image"}`, formData, "POST", true, "multipart/form-data") .then(res => { setState({ loading: false, data: res.data }) if(image.isLogo) { - updateField("logo_id", res.data.id) + updateField("imageId", res.data.id) } else { addValueToFormArray("images", res.data.id) } @@ -129,13 +127,17 @@ const AddProjectModal = ({ isOpen, toggle }) => { } const validateForm = () => { - let valid = true + let valid = true, invalidKeys = [] Object.keys(form).forEach(key => { - if(typeof(form[key]) === "string" && (key !== "images" || key !== "tools" || key !== "logo_id") && form[key].length === 0) + if(typeof(form[key]) === "string" && (key !== "images" && key !== "tools" && key !== "imageId") && form[key].length === 0) { valid = false + invalidKeys.push(key); + } }) + if (invalidKeys.length > 0) console.log(`Invalid keys: ${invalidKeys.join(', ')}`) + return valid } @@ -162,8 +164,8 @@ const AddProjectModal = ({ isOpen, toggle }) => { name: "", description: "", url: "", - repo_url: "", - logo_id: "", + repoURL: "", + imageId: "", images: [], tools: [] }) @@ -201,7 +203,7 @@ const AddProjectModal = ({ isOpen, toggle }) => { if(!tools.data) { request("/portfolio/tool", null, "GET", true) .then(res => { - setTools({ data: res.data.tools }) + setTools({ data: res.data }) }) .catch(err => setTools({ error: err })) } @@ -250,7 +252,7 @@ const AddProjectModal = ({ isOpen, toggle }) => {
- updateField("repo_url", e.target.value)} /> + updateField("repoURL", e.target.value)} /> @@ -299,7 +301,7 @@ const AddProjectModal = ({ isOpen, toggle }) => { - +

Add Tool

@@ -354,7 +356,7 @@ const EditProjectModal = ({ isOpen, toggle, id }) => { setState({ loading: true, data: null, error: null }) - request(`/portfolio/project`, { id }, "DELETE", true) + request(`/portfolio/project/${id}`, null, "DELETE", true) .then(res => { setState({ loading: false, data: res.data }) @@ -396,21 +398,21 @@ const EditProjectModal = ({ isOpen, toggle, id }) => { } const ProjectCard = ({ project, toggleModal }) => { - const { id, name, description, url, repo_url, logo_url } = project + const { id, name, description, url, repoURL, logoURL } = project return ( - +

{name}

- {repo_url && + {repoURL &&

- - {repo_url.includes("github") ? + + {repoURL.includes("github") ? <>GitHub{" "} : <>Repository{" "} @@ -498,10 +500,10 @@ export const ProjectTab = props => { {!state.loading && state.data ? <> - {state.data.projects.length == 0 && + {state.data.length == 0 &&

No project data found...

} - {state.data.projects.length > 0 && state.data.projects.map((project, i) => ( + {state.data.length > 0 && state.data.map((project, i) => ( 1 ? " mt-3" : ""}`}> openEditModal(e, id)} /> diff --git a/src/pages/EditPortfolio/ResumeTab.jsx b/src/pages/EditPortfolio/ResumeTab.jsx index 5d569a2..f1d3fef 100644 --- a/src/pages/EditPortfolio/ResumeTab.jsx +++ b/src/pages/EditPortfolio/ResumeTab.jsx @@ -10,7 +10,7 @@ import { request } from "../../api" const AddResumeModal = ({ isOpen, toggle }) => { const [form, setForm] = useState({ resume_id: "", - creation_date: new Date() + creationDate: new Date() }) const [file, setFile] = useState(null) const [state, setState] = useState({ @@ -40,7 +40,7 @@ const AddResumeModal = ({ isOpen, toggle }) => { return var formData = new FormData() - formData.append("resume", file) + formData.append("file", file) setState({ ...state, loading: true }) @@ -100,7 +100,7 @@ const AddResumeModal = ({ isOpen, toggle }) => { - updateField("creation_date", e.target.value)} /> + updateField("creationDate", e.target.value)} />
@@ -140,7 +140,7 @@ const DeleteResumeModal = ({ isOpen, toggle, resume }) => { setState({ ...state, loading: true }) - request("/portfolio/resume", { id: resume.id }, "DELETE", true) + request(`/portfolio/resume/${resume.id}`, null, "DELETE", true) .then(res => { setState({ ...state, loading: false, data: res.data }) @@ -156,7 +156,7 @@ const DeleteResumeModal = ({ isOpen, toggle, resume }) => { -

{resume && resume.file_name ? resume.file_name : "TBD"}

+

{resume && resume.fileName ? resume.fileName : "TBD"}

Resume Identifier: {resume && resume.id ? resume.id : "N/A"}

Delete this resume?

@@ -224,10 +224,8 @@ export const ResumeTab = props => { .catch(err => setState({ ...state, loading: false, error: err })) } - if(state.data && state.data.resumes && state.data.resumes.length > 0 && !resume) - setResume(state.data.resumes[0]) - - // console.log(state) + if(state.data && state.data && state.data.length > 0 && !resume) + setResume(state.data[0]) return ( <> @@ -246,20 +244,20 @@ export const ResumeTab = props => { {!state.loading && state.data ? <> - {state.data.resumes.length == 0 && + {state.data.length == 0 &&

No resume data found...

}
- {!resume ? "Select Image" : resume.file_name} + {!resume ? "Select Image" : resume.fileName} - {state.data.resumes.length === 0 && + {state.data.length === 0 && N/A } - {state.data.resumes.length > 0 && state.data.resumes.map((obj, i) => ( - updateSelectedResume(e, obj)}>{obj.file_name} + {state.data.length > 0 && state.data.map((obj, i) => ( + updateSelectedResume(e, obj)}>{obj.fileName} ))} diff --git a/src/pages/EditPortfolio/ToolTab.jsx b/src/pages/EditPortfolio/ToolTab.jsx index 28c3748..b97fda3 100644 --- a/src/pages/EditPortfolio/ToolTab.jsx +++ b/src/pages/EditPortfolio/ToolTab.jsx @@ -15,7 +15,7 @@ const AddToolModal = ({ isOpen, toggle }) => { name: "", url: "", description: "", - logo_id: "", + imageId: "", category: "" }) const [description, setDescription] = useState("") @@ -42,7 +42,7 @@ const AddToolModal = ({ isOpen, toggle }) => { name: "", url: "", description: "", - logo_id: "", + imageId: "", category: "" }) setDescription("") @@ -80,15 +80,15 @@ const AddToolModal = ({ isOpen, toggle }) => { return var formData = new FormData() - formData.append("logo", logo) + formData.append("file", logo) setState({ loading: true }) - request("/portfolio/tool/upload-image", formData, "POST", true, "multipart/form-data") + request("/portfolio/tool/logo", formData, "POST", true, "multipart/form-data") .then(res => { setState({ loading: false, data: res.data }) - updateField("logo_id", res.data.id) + updateField("imageId", res.data.id) }) .catch(err => setState({ loading: false, error: err })) } @@ -100,7 +100,7 @@ const AddToolModal = ({ isOpen, toggle }) => { let valid = true Object.keys(form).forEach(key => { - if(typeof(form[key]) === "string" && (key !== "category" || key !== "logo_id") && form[key].length === 0) + if(typeof(form[key]) === "string" && (key !== "category" || key !== "imageId") && form[key].length === 0) valid = false }) @@ -146,7 +146,7 @@ const AddToolModal = ({ isOpen, toggle }) => {

Upload Logo

updateImage(e)} /> - Image Identifier: {form.logo_id ? form.logo_id : "N/A"} + Image Identifier: {form.imageId ? form.imageId : "N/A"}
@@ -165,7 +165,7 @@ const AddToolModal = ({ isOpen, toggle }) => { updateField("category", "")}>New Category {categories.data && categories.data.length > 0 && categories.data.map((obj, i) => ( - updateField("category", obj)}>{obj} + updateField("category", obj.name)}>{obj.name} ))} @@ -203,7 +203,7 @@ const EditToolModal = ({ isOpen, toggle, id }) => { name: "", url: "", description: "", - logo_id: "", + imageId: "", category: "" }) const [description, setDescription] = useState("") @@ -221,7 +221,7 @@ const EditToolModal = ({ isOpen, toggle, id }) => { const [loaded, setLoaded] = useState({ isLoaded: false, original_data: null, - logo_url: "", + imageId: "", error: null }) @@ -236,7 +236,7 @@ const EditToolModal = ({ isOpen, toggle, id }) => { name: "", url: "", description: "", - logo_id: "", + imageId: "", category: "" }) setDescription("") @@ -254,7 +254,7 @@ const EditToolModal = ({ isOpen, toggle, id }) => { setLoaded({ isLoaded: false, original_data: null, - logo_url: "", + logoURL: "", error: null }) @@ -280,45 +280,42 @@ const EditToolModal = ({ isOpen, toggle, id }) => { return var formData = new FormData() - formData.append("logo", logo) + formData.append("file", logo) setState({ loading: true }) - request("/portfolio/tool/upload-image", formData, "POST", true, "multipart/form-data") + request("/portfolio/tool/logo", formData, "POST", true, "multipart/form-data") .then(res => { setState({ loading: false, data: res.data }) - updateField("logo_id", res.data.id) + updateField("imageId", res.data.id) }) .catch(err => setState({ loading: false, error: err })) } - const validateFormAndCondense = () => { + const validateForm = () => { if(description !== "") updateField("description", description) - let valid = true, condensedForm = {} + let valid = true Object.keys(form).forEach(key => { - if(typeof(form[key]) === "string" && (key !== "category" || key !== "logo_id") && form[key].length === 0) + if(typeof(form[key]) === "string" && (key !== "category" || key !== "imageId") && form[key].length === 0) valid = false - else if(typeof(form[key]) === "string" && form[key].length > 0 && form[key] !== loaded.original_data[key]) - condensedForm[key] = form[key] }) - return { condensedForm, isValid: valid } + return valid } const submitData = e => { e.preventDefault() - const { condensedForm, isValid } = validateFormAndCondense() - - if(!isValid) return + if(!validateForm()) + return setState({ loading: true, data: null, error: null }) - request(`/portfolio/tool/${id}`, condensedForm, "PATCH", true) + request(`/portfolio/tool/${id}`, form, "PATCH", true) .then(res => { setState({ loading: false, data: res.data }) @@ -332,7 +329,7 @@ const EditToolModal = ({ isOpen, toggle, id }) => { setState({ loading: true, data: null, error: null }) - request(`/portfolio/tool`, { id }, "DELETE", true) + request(`/portfolio/tool/${id}`, null, "DELETE", true) .then(res => { setState({ loading: false, data: res.data }) @@ -366,7 +363,7 @@ const EditToolModal = ({ isOpen, toggle, id }) => { if(res.data.description) setDescription(res.data.description) - setLoaded({ isLoaded: true, logo_url: res.data.logo_url, original_data: res.data }) + setLoaded({ isLoaded: true, logoURL: res.data.logoURL, original_data: res.data }) }) .catch(err => setLoaded({ error: err })) } @@ -379,13 +376,13 @@ const EditToolModal = ({ isOpen, toggle, id }) => { - +

Upload Logo

updateImage(e)} /> - Image Identifier: {form.logo_id ? form.logo_id : "N/A"} + Image Identifier: {form.imageId ? form.imageId : "N/A"}
@@ -404,7 +401,7 @@ const EditToolModal = ({ isOpen, toggle, id }) => { updateField("category", "")}>New Category {categories.data && categories.data.length > 0 && categories.data.map((obj, i) => ( - updateField("category", obj)}>{obj} + updateField("category", obj.name)}>{obj.name} ))} @@ -439,14 +436,14 @@ const EditToolModal = ({ isOpen, toggle, id }) => { } const ToolCard = ({ tool, toggleModal }) => { - const { id, name, url, description, logo_url, category } = tool + const { id, name, url, description, logoURL, category } = tool return ( - +

{name}

@@ -531,10 +528,10 @@ export const ToolTab = props => { {!state.loading && state.data ? <> - {state.data.tools.length == 0 && + {state.data.length == 0 &&

No tool data found...

} - {state.data.tools.length > 0 && state.data.tools.map((tool, i) => ( + {state.data.length > 0 && state.data.map((tool, i) => ( 1 ? " mt-3" : ""}`}> openEditModal(e, id)} />