export type FormState = {
success: string | undefined
errors: {
message?: string | undefined
}
}
export const deleteEducation = async (previousState: FormState, formData: FormData) => {
console.log(formData)
try {
const session = await auth()
if (!session) {
return {
success: undefined,
errors: {
message: 'Not authenticated',
},
}
}
const id = formData.get('id')
console.log(id)
if (!id) {
return {
success: undefined,
errors: {
message: 'Failed to delete education record',
},
}
}
const result = await prisma.education.delete({
where: { id: String(id) },
})
revalidatePath('/intern/profile')
if (result) {
return {
success: 'Education record deleted successfully',
errors: {
message: undefined,
},
}
}
} catch (e) {
console.log(e)
return null
}
}
import { deleteEducation, FormState } from '@/lib/actions'
const initialState = {
success: '',
errors: {
message: '',
},
} as FormState
export default function DeleteEducation({ id, institution, major, startDate, endDate, honors }: DeleteEducationProps) {
unstable_noStore()
const [formState, removeEducationRecord] = useFormState(deleteEducation, initialState)