Add e-payment UI, checkout payment result, and legacy migrate domain lookup.

Wire Mellat settings in business dashboard, customer bank return page with payment details, and super-admin migrate modal domain confirmation.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Alireza Hassani
2026-08-13 09:51:22 +03:30
co-authored by Cursor
parent a11f9643bb
commit cc94b929e0
54 changed files with 6415 additions and 96 deletions
@@ -0,0 +1,231 @@
import { useEffect, useState } from 'react'
import { useNavigate } from 'react-router-dom'
import { Play, Plus } from 'lucide-react'
import { Breadcrumbs } from '../components/Breadcrumbs'
import { PageTitle } from '../components/PageTitle'
import { InstructionCard } from '../components/InstructionCard'
import { InstructionCommentsModal } from '../components/InstructionCommentsModal'
import { ConfirmDeleteModal } from '../components/ConfirmDeleteModal'
import { Pagination } from '../components/Pagination'
import { useToast } from '../context/ToastContext'
import { useT } from '../i18n/useT'
import { useLocale } from '@meshkee/dashboard-ui'
import { ApiError } from '../lib/api'
import {
INSTRUCTIONS_PER_PAGE,
deleteInstruction,
listInstructions,
resolveInstructionTitle,
} from '../services/instructionService'
import type { Video } from '../types/instruction'
import pageStyles from '../components/PageContent.module.css'
import styles from './BlogPage.module.css'
export function InstructionListPage() {
const navigate = useNavigate()
const { showToast } = useToast()
const t = useT()
const { locale } = useLocale()
const [videos, setInstructions] = useState<Video[]>([])
const [totalInstructions, setTotalVideos] = useState(0)
const [currentPage, setCurrentPage] = useState(1)
const [isLoading, setIsLoading] = useState(true)
const [isDeleting, setIsDeleting] = useState(false)
const [error, setError] = useState('')
const [commentCounts, setCommentCounts] = useState<Record<string, number>>({})
const [deleteTarget, setDeleteTarget] = useState<{ id: string; title: string } | null>(null)
const [commentsTarget, setCommentsTarget] = useState<{ id: string; title: string } | null>(null)
const totalPages = Math.max(1, Math.ceil(totalInstructions / INSTRUCTIONS_PER_PAGE))
useEffect(() => {
const controller = new AbortController()
void loadVideos(currentPage, controller.signal)
return () => controller.abort()
}, [currentPage])
async function loadVideos(page: number, signal?: AbortSignal) {
setIsLoading(true)
setError('')
try {
const data = await listInstructions(page, INSTRUCTIONS_PER_PAGE, signal)
setInstructions(data.items)
setTotalVideos(data.total)
setCommentCounts(
Object.fromEntries(data.items.map((video) => [video.id, video.commentCount ?? 0])),
)
} catch (err) {
if (err instanceof DOMException && err.name === 'AbortError') return
if (err instanceof ApiError) {
setError(err.message)
} else {
setError(t('instruction.list.errorLoad'))
}
} finally {
setIsLoading(false)
}
}
function handleEdit(id: string) {
navigate(`/instructions/edit/${id}`)
}
function handleComments(id: string) {
const video = videos.find((item) => item.id === id)
if (video) {
setCommentsTarget({
id,
title: resolveInstructionTitle(video, locale === 'fa' ? 'fa' : 'en'),
})
}
}
function handleRemoveRequest(id: string) {
const video = videos.find((item) => item.id === id)
if (video) {
setDeleteTarget({
id,
title: resolveInstructionTitle(video, locale === 'fa' ? 'fa' : 'en'),
})
}
}
async function confirmDelete() {
if (!deleteTarget) return
setIsDeleting(true)
setError('')
try {
await deleteInstruction(deleteTarget.id)
showToast(t('instruction.list.toast.removed'), 'success')
const nextTotal = totalInstructions - 1
const nextTotalPages = Math.max(1, Math.ceil(nextTotal / INSTRUCTIONS_PER_PAGE))
const nextPage = currentPage > nextTotalPages ? nextTotalPages : currentPage
setDeleteTarget(null)
setCurrentPage(nextPage)
await loadVideos(nextPage)
} catch (err) {
if (err instanceof ApiError) {
setError(err.message)
} else {
setError(t('instruction.list.errorDelete'))
}
} finally {
setIsDeleting(false)
}
}
function handlePageChange(page: number) {
setCurrentPage(page)
window.scrollTo({ top: 0, behavior: 'smooth' })
}
function handleCommentCountChange(count: number) {
if (!commentsTarget) return
setCommentCounts((prev) => ({
...prev,
[commentsTarget.id]: count,
}))
}
return (
<main className={pageStyles.content}>
<Breadcrumbs
items={[
{ label: 'Dashboard', href: '/' },
{ label: 'Instructions', href: '/instructions' },
{ label: 'My Instructions' },
]}
/>
<div className={pageStyles.pageHeader}>
<div>
<PageTitle en="MY INSTRUCTIONS">{t('title.myInstructions')}</PageTitle>
<p className={pageStyles.pageSubtitle}>
{t('instruction.list.subtitle', { count: totalInstructions })}
</p>
</div>
</div>
{error && (
<div className={styles.error} role="alert">
{error}
</div>
)}
{isLoading ? (
<p className={styles.empty}>{t('instruction.list.loading')}</p>
) : videos.length === 0 ? (
<div className={styles.emptyState}>
<div className={styles.emptyIcon} aria-hidden="true">
<Play size={28} strokeWidth={1.75} />
</div>
<h3 className={styles.emptyTitle}>{t('instruction.list.empty')}</h3>
<p className={styles.emptyHint}>{t('instruction.list.emptyHint')}</p>
<button
type="button"
className={styles.emptyCta}
onClick={() => navigate('/instructions/new')}
>
<Plus size={18} strokeWidth={2.25} />
{t('instruction.list.emptyCta')}
</button>
</div>
) : (
<>
<div className={pageStyles.grid}>
{videos.map((video) => (
<InstructionCard
key={video.id}
video={video}
commentCount={commentCounts[video.id] ?? video.commentCount}
onEdit={handleEdit}
onComments={handleComments}
onRemove={handleRemoveRequest}
/>
))}
</div>
<Pagination
currentPage={currentPage}
totalPages={totalPages}
onPageChange={handlePageChange}
/>
</>
)}
<button
type="button"
className={styles.addFab}
onClick={() => navigate('/instructions/new')}
aria-label={t('instruction.list.addNew')}
>
<Plus size={26} strokeWidth={2.5} />
</button>
<ConfirmDeleteModal
open={!!deleteTarget}
title={t('instruction.list.deleteTitle')}
message={
deleteTarget
? t('instruction.list.deleteMessage', { name: deleteTarget.title })
: ''
}
onConfirm={confirmDelete}
onCancel={() => !isDeleting && setDeleteTarget(null)}
/>
{commentsTarget && (
<InstructionCommentsModal
open={!!commentsTarget}
instructionId={commentsTarget.id}
instructionTitle={commentsTarget.title}
onClose={() => setCommentsTarget(null)}
onCountChange={handleCommentCountChange}
/>
)}
</main>
)
}