I received a reply saying that the applyGroup
function does not return anything, so no properties were called at that time.
If so, will it be sent if it is not imported from other components and is used from the same component?
This is a question I wrote before.
import { BASE_URL, accessToken } from "../../Apis/Common";
const handleSubmit = async (e) => {
e.preventDefault();
switch (buttonStatus) {
case "apply":
if (modalData.day.length === 0 || modalData.role === '' || !linkButtonDisable) {
alert('all typing');
if (modalData.day.length === 0) {
setIsDayValid(false);
} else {
setIsDayValid(true);
}
if (modalData.role === '') {
setIsSelectRoldValid(false);
} else {
setIsSelectRoldValid(true);
}
if (!linkButtonDisable) {
setIsPortfolioTextValid(false);
} else {
setIsPortfolioTextValid(true);
}
} else {
alert('send');
setIsDayValid(true);
setIsSelectRoldValid(true);
try {
const formData = new FormData();
formData.append("name", modalData.name);
formData.append("email", modalData.email);
formData.append("role", modalData.role);
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("language", modalData.language);
const response = await axios.post(
`${BASE_URL}/post/${groupId}/apply`,
formData
);
alert("done");
onClose();
} catch (error) {
console.error(
"fail:",
error.response ? error.response.data : error.message
);
alert("fail. try");
}
}
break;
case "done":
alert("done");
onClose();
break;
case "reject":
alert("reject");
onClose();
break;
}
};
If I connect it directly to formdata in this way, will it become a post?
And I need to get the groupId from the backend but I don’t know how to get it..
const groupResponse = await axios.get(`${BASE_URL}/post/${groupId}`);
const groupId = groupResponse.data.groupId;
I was going to call it like this, but it didn’t reset.
Axios is so hard…