Files
approagency-admin-panel/components/admin/referral/ReferralList.tsx
T
2026-06-06 13:50:06 +03:30

91 lines
4.6 KiB
TypeScript

'use client';
import { ReferralRewardUser } from '@/types/referral';
import { GiftIcon, EnvelopeIcon, PhoneIcon, TicketIcon, UserIcon } from '@heroicons/react/24/outline';
interface ReferralListProps {
users: ReferralRewardUser[];
subscriptionTarget: number;
onFulfill: (user: ReferralRewardUser) => void;
isLoading: boolean;
fulfillingId: number | null;
}
export default function ReferralList({
users,
subscriptionTarget,
onFulfill,
isLoading,
fulfillingId
}: ReferralListProps) {
if (users.length === 0) {
return (
<div className="text-center py-12 bg-white rounded-lg shadow">
<GiftIcon className="h-10 w-10 text-gray-300 mx-auto mb-3" />
<p className="text-gray-500">
در حال حاضر هیچ کاربری واجد شرایط دریافت پاداش معرفی نیست.
</p>
<p className="text-sm text-gray-400 mt-1">
کاربران پس از {subscriptionTarget} دعوت موفق در این لیست نمایش داده می‌شوند.
</p>
</div>
);
}
return (
<div className="bg-white shadow overflow-hidden sm:rounded-lg">
<div className="px-4 py-5 sm:px-6 flex items-center justify-between">
<h3 className="text-lg leading-6 font-medium text-gray-900">
کاربران واجد شرایط پاداش
</h3>
<span className="px-3 py-1 text-xs font-medium rounded-full bg-indigo-100 text-indigo-800">
هدف: {subscriptionTarget} دعوت موفق
</span>
</div>
<ul className="divide-y divide-gray-200 border-t border-gray-200">
{users.map((user) => (
<li key={user.id} className="px-4 py-4 sm:px-6">
<div className="flex items-center justify-between flex-wrap gap-3">
<div className="flex-1 min-w-0">
<div className="flex items-center gap-2">
<UserIcon className="h-4 w-4 text-gray-400" />
<p className="text-sm font-medium text-gray-900 truncate">
{user.name || 'بدون نام'}
</p>
<span className="px-2 py-0.5 text-xs font-semibold rounded-full bg-green-100 text-green-800">
{user.successful_invites} دعوت موفق
</span>
</div>
<div className="mt-2 flex flex-wrap gap-x-6 gap-y-1 text-sm text-gray-500">
<span className="flex items-center">
<EnvelopeIcon className="h-4 w-4 ml-1 text-gray-400" />
{user.email || 'ایمیل ثبت نشده'}
</span>
<span className="flex items-center">
<PhoneIcon className="h-4 w-4 ml-1 text-gray-400" />
{user.mobile || 'شماره ثبت نشده'}
</span>
{user.referral_code && (
<span className="flex items-center">
<TicketIcon className="h-4 w-4 ml-1 text-gray-400" />
کد معرف: {user.referral_code}
</span>
)}
</div>
</div>
<button
onClick={() => onFulfill(user)}
disabled={isLoading}
className="inline-flex items-center px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-green-600 hover:bg-green-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-green-500 disabled:opacity-50 disabled:cursor-not-allowed"
>
<GiftIcon className="h-5 w-5 ml-2" />
{fulfillingId === user.id ? 'در حال اعطا...' : 'اعطای اشتراک رایگان'}
</button>
</div>
</li>
))}
</ul>
</div>
);
}