I used axios.post , but I wrote down the data to send, put it in the transfer button, and ran it, and it didn’t work. So I checked with console.log, but the data didn’t have a value. I don’t know why.
This is an axios post function.
export function applyGroup(groupId, applyment){
axios.post(`${BASE_URL}/post/${groupId}/apply`,{
email: applyment.email,
position: applyment.position,
applicationReason: applyment.application_reason,
introduction: applyment.introduction,
techStack: applyment.tech_stack,
portfolioLink: applyment.portfolio_link,
availableDays: applyment.available_days,
additionalNotes: applyment.additional_notes
},{
headers:{
Authorization: accessToken
}
})
.then(function(response){
console.log(response);
})
.catch(function(error){
console.log(error);
});
}
This is the data transfer code added to the button.
const ApplicantModal = ({ onClose, onSubmit, applicant, isView, groupId }) => {
const [modalData, setModalData] = useState(
applicant || {
//name: "",
email: "",
position: "",
reason: "",
portfolioLink: "",
date: "",
introduce: "",
//freeEntry: "",
day: [],
techStack: "",
}
);
///post/{postId}/apply
const handleSubmit = async (e) => {
e.preventDefault();
switch (buttonStatus) {
case "apply":
if (modalData.day.length === 0 || modalData.position === '' || !linkButtonDisable) {
alert('all typing required');
if (modalData.day.length === 0) {
setIsDayValid(false);
} else {
setIsDayValid(true);
}
if (modalData.position === '') {
setIsSelectRoldValid(false);
} else {
setIsSelectRoldValid(true);
}
if (!linkButtonDisable) {
setIsPortfolioTextValid(false);
} else {
setIsPortfolioTextValid(true);
}
} else {
alert('done');
setIsDayValid(true);
setIsSelectRoldValid(true);
const formData = new FormData();
//formData.append("name", modalData.name);
formData.append("email", modalData.email);
formData.append("position", modalData.position);
formData.append("reason", modalData.reason);
formData.append("portfolioLink", modalData.portfolioLink);
//formData.append("date", modalData.date);
formData.append("introduce", modalData.introduce);
//formData.append("freeEntry", modalData.freeEntry);
formData.append("day", modalData.day);
formData.append("techStack", modalData.techStack);
applyGroup(groupId, formData)
.then((response) => {
alert("apply done");
console.log("request data:", response.data);
setModalData({});
onClose();
})
.catch((error) => {
console.error("fail:", error.response ? error.response.data : error.message);
alert("error. trying");
});
}
break;
default:
alert("bad");
break;
}
};
This is an error code.
Cannot read properties of undefined (reading 'then')
TypeError: Cannot read properties of undefined (reading 'then')
at handleSubmit (http://localhost:3000/main.2e8d1140a2de14e5442f.hot-update.js:157:93)
at HTMLUnknownElement.callCallback (http://localhost:3000/static/js/bundle.js:81475:18)
at Object.invokeGuardedCallbackDev (http://localhost:3000/static/js/bundle.js:81519:20)
at invokeGuardedCallback (http://localhost:3000/static/js/bundle.js:81576:35)
at invokeGuardedCallbackAndCatchFirstError (http://localhost:3000/static/js/bundle.js:81590:29)
at executeDispatch (http://localhost:3000/static/js/bundle.js:85733:7)
at processDispatchQueueItemsInOrder (http://localhost:3000/static/js/bundle.js:85759:11)
at processDispatchQueue (http://localhost:3000/static/js/bundle.js:85770:9)
at dispatchEventsForPlugins (http://localhost:3000/static/js/bundle.js:85779:7)
at http://localhost:3000/static/js/bundle.js:85939:16
Please save the poor student.
You need to sign in to view this answers