Next.js Discord

Discord Forum

Server Side Delete Confirmation

Unanswered
Horned oak gall posted this in #help-forum
Open in Discord
Horned oak gallOP
Hello, I have a question, would it be possible to add a delete confirmation on the server side of next js or would that make it a client side component

13 Replies

@Horned oak gall by confirmation, did you mean sort of pop ups where you can confirm or decline?
then it should be on the client end
on the server side, you can't have user interactions/event handlers
Horned oak gallOP
"use client"
import { deleteTask } from '@/utils/actions'
import React from 'react'
const DeleteForm = async ({ id }) => {

const handleDelete = (e) => {
e.preventDefault()
let confirm = confirm('Are you sure you want to delete this task?')
if (confirm) {
deleteTask(new FormData(e.target))
}
}

return (
<form onSubmit={handleDelete} >
<input type='hidden' name='id' value={id} />
<button type="submit" className='btn btn-xs btn-error '>Delete</button>
</form >
)
}
export default DeleteForm
Trying this it breaks
const handleDelete = (e) => {
    e.preventDefault()
    let confirm = confirm('Are you sure you want to delete this task?')
    if (confirm) {
      deleteTask(new FormData(e.target))
    }
  }
it's not correct
create your popup modal and then invoke your server action from your dialog when they click on "agree" button
Horned oak gallOP
Thanks
"use client"
import { deleteTask } from '@/utils/actions'
import React from 'react'
const DeleteForm = ({ id }) => {

const handleDelete = async (e) => {
e.preventDefault()
const confirmed = confirm('Are you sure you want to delete this task?')
if (confirmed) {
deleteTask(new FormData(e.target))
} else {
alert('Task not deleted.')
}
}

return (
<form onSubmit={handleDelete} >
<input type='hidden' name='id' value={id} />
<button type="submit" className='btn btn-xs btn-error '>Delete</button>
</form >
)
}
export default DeleteForm
I did this so far