Skip to content

Commit

Permalink
finished add personalType and modify Field of input personaltype
Browse files Browse the repository at this point in the history
  • Loading branch information
satanakorn committed Nov 25, 2024
1 parent d4a5425 commit 621b2b4
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 23 deletions.
62 changes: 48 additions & 14 deletions frontend/src/profile.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const EditProfileModal = ({ isOpen, onClose, onSave, user }) => {

Swal.fire({
title: "Good job!",
text: "Register Sucessful!",
text: "Update Profile successful!",
icon: "success"
});
setTimeout(() => {
Expand Down Expand Up @@ -197,39 +197,73 @@ AddSkillModal.propTypes = {
onSave: PropTypes.func.isRequired,
};


// AddPersonalTypeModal component
const AddPersonalTypeModal = ({ isOpen, onClose, onSave }) => {
const [personalType, setPersonalType] = useState('');
const [personalTypeDetail, setPersonalTypeDetail] = useState('');

const handleSubmit = () => {
onSave(personalType);
const handleSubmit = async () => {
try {
const createResponse = await Axios.post('http://localhost:3000/personal/create', {
personalType,
personalTypeDetail,
});

const newPersonalType = createResponse.data;

const userID = localStorage.getItem('UserID');
await Axios.post('http://localhost:3000/personal/addToUser', {
userID,
personalTypeID: newPersonalType.PersonalTypeID,
});

onSave(newPersonalType);

Swal.fire({
title: "Good job!",
text: "Personal Type Added Successfully!",
icon: "success"
});
setTimeout(() => {
Swal.close();
}, 3000);

onClose();
} catch (error) {
console.error('Error creating personal type:', error);
}
};

if (!isOpen) return null;

return (
<div className="fixed inset-0 flex items-center justify-center bg-black bg-opacity-50 z-50">
<div className="w-full max-w-md bg-gradient-to-b from-bluebg to-skybg text-white rounded-lg p-5 shadow-lg">
<form onSubmit={(e) => e.preventDefault()}>
<form onSubmit={(e) => e.preventDefault()}>
<h1 className="text-4xl font-bold text-center mb-6">Add Personal Type</h1>
<div className="relative mb-4">

<a
href='https://www.arealme.com/disc-personality-test/th/'
target="_blank"
rel="noopener noreferrer"
className="mb-5 w-full block text-center px-4 py-3 bg-red-500 text-white rounded-lg hover:bg-red-600 transition duration-300"
>
ประเมิน personal type
</a>

<a
href='https://www.arealme.com/disc-personality-test/th/'
target="_blank"
rel="noopener noreferrer"
className="mb-5 w-full block text-center px-4 py-3 bg-red-500 text-white rounded-lg hover:bg-red-600 transition duration-300"
>
ประเมิน personal type
</a>
<input
type="text"
placeholder="กรอกผลลัพธ์ Personal Type"
required
className="w-full h-12 px-4 py-2 bg-transparent border border-white rounded-full text-white placeholder-white focus:outline-none focus:border-white"
onChange={(e) => setPersonalType(e.target.value)}
/>
<textarea
placeholder="รายละเอียด Personal Type"
required
className="w-full h-32 px-4 py-2 mt-4 bg-transparent border border-white rounded-lg text-white placeholder-white focus:outline-none focus:border-white resize-none"
onChange={(e) => setPersonalTypeDetail(e.target.value)}
/>
</div>
<div className="flex justify-between mt-6">
<button
Expand Down
16 changes: 7 additions & 9 deletions src/controllers/personalController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,8 @@ export const personalController = new Elysia({ prefix: "/personal" })
return error(404, "User not found");
}

// Get all personal information of the user
const personal = await prisma.user.findMany({
where: { UserID: userID },
});

// Get the personalTypeID of the user
const personalTypeID = personal.length > 0 ? personal[0].PersonalTypeID : null;
const personalTypeID = user.PersonalTypeID;

if (!personalTypeID) {
return error(404, "Personal type not found");
Expand All @@ -33,6 +28,10 @@ export const personalController = new Elysia({ prefix: "/personal" })
where: { PersonalTypeID: personalTypeID },
});

if (!personalType) {
return error(404, "Personal type not found");
}

// Return the json of the userID and the personalType
return {
userID: userID,
Expand Down Expand Up @@ -140,7 +139,7 @@ export const personalController = new Elysia({ prefix: "/personal" })
}),
})

// delete the user
// Delete the personal type of the user
.delete('/:userID', async ({ params, error }) => {
const { userID } = params;

Expand All @@ -162,9 +161,8 @@ export const personalController = new Elysia({ prefix: "/personal" })
});

return updatedPersonal;

}, {
params: t.Object({
userID: t.String(),
}),
})
})

0 comments on commit 621b2b4

Please sign in to comment.