Files
gruperly/apps/web/src/features/groups/detail/InviteLinkModal.tsx
2026-11-03 12:25:21 -03:00

124 lines
4.5 KiB
TypeScript

import { Copy, Loader2, MessageCircle, RefreshCw } from 'lucide-react'
import { Trans, useTranslation } from 'react-i18next'
import { Button, Input, Label, Modal } from '../../../components/ui'
import { cn } from '../../../lib/utils'
import { useGroupDetail } from './GroupDetailProvider'
export function InviteLinkModal() {
const {
isInviteModalOpen,
closeInviteModal,
group,
inviteUrl,
invitePending,
isRegeneratingInvite,
regenerateInvite,
copyInviteLink,
copyWhatsappMessage,
openWhatsapp,
} = useGroupDetail()
const { t } = useTranslation('groupDetail')
return (
<Modal
isOpen={isInviteModalOpen}
onClose={closeInviteModal}
title={t('invite.title')}
description={t('invite.description')}
maxWidth="md"
>
<div className="space-y-5">
{invitePending ? (
<div className="flex items-center justify-center py-6">
<Loader2 className="size-6 animate-spin text-accent" />
</div>
) : (
<>
<div>
<Label htmlFor="invite-link-input" className="mb-1.5 block">
{t('invite.linkLabel')}
</Label>
<div className="flex items-center gap-2">
<Input
id="invite-link-input"
readOnly
value={inviteUrl ?? ''}
className="select-text bg-primary-soft/50 font-mono text-xs"
/>
<Button
variant="outline"
onClick={() => void copyInviteLink()}
className="shrink-0 gap-1.5 px-3"
title={t('invite.copyTitle')}
>
<Copy className="size-4" />
<span>{t('invite.copy')}</span>
</Button>
</div>
</div>
<div className="space-y-2.5 rounded-xl border border-accent/20 bg-accent-soft p-4 text-xs text-foreground/80">
<div className="flex items-center justify-between gap-2">
<p className="font-semibold text-primary">{t('invite.previewTitle')}</p>
<Button
type="button"
variant="ghost"
size="sm"
onClick={() => void copyWhatsappMessage()}
className="h-7 shrink-0 gap-1.5 px-2 text-xs text-primary hover:text-primary/80"
title={t('invite.copyMessageTitle')}
>
<Copy className="size-3.5" />
<span>{t('invite.copyMessage')}</span>
</Button>
</div>
<div className="whitespace-pre-line rounded-lg border border-accent/10 bg-surface/70 p-3 font-sans text-xs leading-relaxed text-foreground">
<Trans
t={t}
i18nKey="invite.messagePreview"
values={{ group: group?.name ?? '' }}
components={{ strong: <strong /> }}
/>
<span className="break-all text-accent underline">{inviteUrl}</span>
</div>
</div>
<div className="flex flex-col items-center gap-2.5 pt-2 sm:flex-row">
<Button
variant="primary"
onClick={() => void openWhatsapp()}
className="w-full gap-2 border-0 bg-[#25D366] text-white hover:bg-[#1EBE5D] sm:flex-1"
>
<MessageCircle className="size-4" />
<span>{t('invite.openWhatsapp')}</span>
</Button>
<Button
variant="ghost"
size="sm"
onClick={regenerateInvite}
disabled={isRegeneratingInvite}
className="w-full gap-1.5 text-xs text-foreground/60 hover:text-danger sm:w-auto"
title={t('invite.regenerateTitle')}
>
<RefreshCw className={cn('size-3.5', isRegeneratingInvite && 'animate-spin')} />
<span>{t('invite.regenerate')}</span>
</Button>
</div>
<p className="text-center text-[11px] font-normal leading-normal text-foreground/50 sm:text-left">
<Trans
t={t}
i18nKey="invite.footnote"
components={{
strong: <strong />,
kbd: <kbd className="rounded bg-primary-soft px-1 py-0.5 font-mono text-[10px] text-primary" />,
}}
/>
</p>
</>
)}
</div>
</Modal>
)
}