admin/hooks/useCopyToClipboard.ts
alisaza e1eaf5eff5 feat: initial ghabilee-admin backoffice app
Extract admin dashboard from ghabilee-frontend2 into a dedicated Next.js
app for backoffice.ghabilee.ir (no SEO indexing / Clarity).
2026-09-05 13:12:59 +03:30

27 lines
807 B
TypeScript

import { addToast } from '@/lib/toast'
/**
* Copies `text` to the clipboard and shows a success/failure toast.
* Was hand-copied (identical try/writeText/toast/catch shape) in
* BookingActionsModal.tsx#handleCopyCode and HostedEventActionsModal.tsx#handleShare —
* this is the shared home for any future "copy X" feature.
*/
const useCopyToClipboard = () => {
const copyToClipboard = async (text: string, messages: { successMessage: string; failureMessage: string }) => {
try {
await navigator.clipboard.writeText(text)
addToast({ title: messages.successMessage, color: 'success' })
return true
} catch {
addToast({ title: messages.failureMessage, color: 'danger' })
return false
}
}
return { copyToClipboard }
}
export default useCopyToClipboard