Extract admin dashboard from ghabilee-frontend2 into a dedicated Next.js app for backoffice.ghabilee.ir (no SEO indexing / Clarity).
80 lines
2.3 KiB
TypeScript
80 lines
2.3 KiB
TypeScript
'use client'
|
||
|
||
import type { AdminEventDetailData } from './types'
|
||
|
||
import { useState } from 'react'
|
||
|
||
import Input from '@/components/formElements/Input'
|
||
import Modal from '@/components/modals/Modal'
|
||
import { coerceToString } from '@/helpers'
|
||
import { rejectEventAsAdmin } from '@/services/events'
|
||
import useAdminAction from '@/hooks/useAdminAction'
|
||
|
||
interface AdminEventRejectModalProps {
|
||
eventId: string
|
||
isOpen: boolean
|
||
onOpenChange: (open: boolean) => void
|
||
onRejected: (updated: AdminEventDetailData) => void
|
||
}
|
||
|
||
const AdminEventRejectModal = ({ eventId, isOpen, onOpenChange, onRejected }: AdminEventRejectModalProps) => {
|
||
const [rejectionReason, setRejectionReason] = useState('')
|
||
const { pendingId, runAction } = useAdminAction()
|
||
|
||
const reset = () => {
|
||
setRejectionReason('')
|
||
}
|
||
|
||
const handleReject = () =>
|
||
runAction(
|
||
'reject',
|
||
async () => {
|
||
const updated = (await rejectEventAsAdmin(eventId, rejectionReason.trim())) as AdminEventDetailData
|
||
|
||
onRejected(updated)
|
||
onOpenChange(false)
|
||
reset()
|
||
},
|
||
'رویداد رد شد و برای اصلاح به پیشنویس بازگشت'
|
||
)
|
||
|
||
return (
|
||
<Modal
|
||
acceptDanger
|
||
acceptBtnDisabled={rejectionReason.trim().length < 3}
|
||
acceptBtnText="رد رویداد"
|
||
isLoading={pendingId === 'reject'}
|
||
isOpen={isOpen}
|
||
rejectBtnText="انصراف"
|
||
size="lg"
|
||
title="رد رویداد"
|
||
onAccept={() => void handleReject()}
|
||
onOpenChange={(open) => {
|
||
onOpenChange(open)
|
||
if (!open) reset()
|
||
}}
|
||
onReject={() => {
|
||
onOpenChange(false)
|
||
reset()
|
||
}}
|
||
>
|
||
<div className="flex flex-col gap-4">
|
||
<p className="text-sm text-text-muted">دلیل رد برای میزبان ارسال میشود تا بتواند رویداد را اصلاح و دوباره برای بررسی ارسال کند.</p>
|
||
<Input
|
||
generalType="textarea"
|
||
label="دلیل رد"
|
||
name="rejectionReason"
|
||
placeholder="حداقل ۳ کاراکتر"
|
||
textAreaMinRows={3}
|
||
value={rejectionReason}
|
||
onValueChange={(value) => {
|
||
setRejectionReason(coerceToString(value))
|
||
}}
|
||
/>
|
||
</div>
|
||
</Modal>
|
||
)
|
||
}
|
||
|
||
export default AdminEventRejectModal
|