feat(user-agreement): implement user agreement upload functionality and update related components

This commit is contained in:
2025-07-25 10:39:15 +05:00
parent 5fda723653
commit c2578f1c8f
9 changed files with 190 additions and 6 deletions

View File

@ -160,4 +160,49 @@ export async function updateUser(
...updatedUser,
message: "User updated successfully",
};
}
export async function updateUserAgreement(
_prevState: UpdateUserFormState,
formData: FormData
): Promise<UpdateUserFormState> {
const userId = formData.get("userId") as string;
// Remove userId from formData before sending to API
const apiFormData = new FormData();
for (const [key, value] of formData.entries()) {
if (key !== "userId") {
apiFormData.append(key, value);
}
}
console.log({ apiFormData })
const session = await getServerSession(authOptions);
const response = await fetch(
`${process.env.SARLINK_API_BASE_URL}/api/auth/users/${userId}/agreement/`,
{
method: "PUT",
headers: {
Authorization: `Token ${session?.apiToken}`,
},
body: apiFormData,
},
);
console.log("response in update user agreement action", response)
if (!response.ok) {
const errorData = await response.json();
return {
message: errorData.message || errorData.detail || "An error occurred while updating the user agreement.",
fieldErrors: errorData.field_errors || {},
payload: formData,
}
}
const updatedUserAgreement = await response.json() as { agreement: string };
revalidatePath("/users/[userId]/update", "page");
revalidatePath("/users/[userId]/verify", "page");
revalidatePath("/users/[userId]/agreement", "page");
return {
...updatedUserAgreement,
message: "User agreement updated successfully",
};
}