I have this form:
<Form action={deleteCandidateAction} spaReset>
<input type="hidden" name="candidateIdFromList" value={candidate.id} />
<button type="submit" class="button-dark">Delete</button>
</Form>
And I'd like to add a simple window.confirm here before executing the action, I've tried doing it in the action, but it doesn't work because it's server side and throws an error for the window object
export const useDeleteCandidateAction = routeAction$(
({candidateIdFromList}, requestEvent) => {
const candidateId = candidateIdFromList as string || getDeepestCandidateId(requestEvent.params.all);
deleteCandidate(candidateId!);
return {
success: true,
};
},
);
I've also tried something like this but it has a typescript error when calling the action:
const confirmDeleteCandidate = (action: ReturnType<typeof useDeleteCandidateAction>) => {
if (window.confirm('Are you sure you want to delete this candidate?')) {
return action();
}
};
What's the general way to achieve this in qwik?