feat: add refferal feature
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
'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>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
'use client';
|
||||
|
||||
import { useState } from 'react';
|
||||
import { User, UpdateUserProfileData } from '@/types/user';
|
||||
import { XMarkIcon } from '@heroicons/react/24/outline';
|
||||
|
||||
interface UserEditFormProps {
|
||||
user: User;
|
||||
onSubmit: (data: UpdateUserProfileData) => void;
|
||||
onCancel: () => void;
|
||||
isLoading: boolean;
|
||||
}
|
||||
|
||||
export default function UserEditForm({ user, onSubmit, onCancel, isLoading }: UserEditFormProps) {
|
||||
const [formData, setFormData] = useState<UpdateUserProfileData>({
|
||||
first_name: user.first_name || '',
|
||||
last_name: user.last_name || '',
|
||||
email: user.email || '',
|
||||
mobile: user.mobile || '',
|
||||
avatar: null,
|
||||
});
|
||||
|
||||
const handleSubmit = (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
|
||||
// Only send changed fields so we never overwrite values with empty ones
|
||||
const payload: UpdateUserProfileData = {};
|
||||
if (formData.first_name !== (user.first_name || '')) payload.first_name = formData.first_name;
|
||||
if (formData.last_name !== (user.last_name || '')) payload.last_name = formData.last_name;
|
||||
if (formData.email !== (user.email || '')) payload.email = formData.email;
|
||||
if (formData.mobile !== (user.mobile || '')) payload.mobile = formData.mobile;
|
||||
if (formData.avatar) payload.avatar = formData.avatar;
|
||||
|
||||
onSubmit(payload);
|
||||
};
|
||||
|
||||
const inputClass =
|
||||
'block w-full px-3 py-2 border text-slate-900 border-gray-300 rounded-md leading-5 bg-white focus:outline-none focus:ring-1 focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm';
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4">
|
||||
<div className="bg-white rounded-lg shadow-xl w-full max-w-lg" dir="rtl">
|
||||
<div className="flex items-center justify-between px-6 py-4 border-b border-gray-200">
|
||||
<h3 className="text-lg font-medium text-gray-900">ویرایش اطلاعات کاربر</h3>
|
||||
<button
|
||||
onClick={onCancel}
|
||||
className="text-gray-400 hover:text-gray-600"
|
||||
type="button"
|
||||
>
|
||||
<XMarkIcon className="h-5 w-5" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<form onSubmit={handleSubmit} className="px-6 py-4 space-y-4">
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 mb-1">نام</label>
|
||||
<input
|
||||
type="text"
|
||||
className={inputClass}
|
||||
value={formData.first_name || ''}
|
||||
onChange={(e) => setFormData({ ...formData, first_name: e.target.value })}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 mb-1">نام خانوادگی</label>
|
||||
<input
|
||||
type="text"
|
||||
className={inputClass}
|
||||
value={formData.last_name || ''}
|
||||
onChange={(e) => setFormData({ ...formData, last_name: e.target.value })}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 mb-1">ایمیل</label>
|
||||
<input
|
||||
type="email"
|
||||
dir="ltr"
|
||||
className={inputClass}
|
||||
value={formData.email || ''}
|
||||
onChange={(e) => setFormData({ ...formData, email: e.target.value })}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 mb-1">شماره موبایل</label>
|
||||
<input
|
||||
type="text"
|
||||
dir="ltr"
|
||||
placeholder="09xxxxxxxxx"
|
||||
className={inputClass}
|
||||
value={formData.mobile || ''}
|
||||
onChange={(e) => setFormData({ ...formData, mobile: e.target.value })}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 mb-1">آواتار</label>
|
||||
<input
|
||||
type="file"
|
||||
accept="image/*"
|
||||
className="block w-full text-sm text-gray-700 file:ml-4 file:py-2 file:px-4 file:rounded-md file:border-0 file:text-sm file:font-medium file:bg-indigo-50 file:text-indigo-700 hover:file:bg-indigo-100"
|
||||
onChange={(e) =>
|
||||
setFormData({ ...formData, avatar: e.target.files?.[0] || null })
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end gap-2 pt-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={onCancel}
|
||||
disabled={isLoading}
|
||||
className="px-4 py-2 border border-gray-300 rounded-md text-sm font-medium text-gray-700 bg-white hover:bg-gray-50 disabled:opacity-50"
|
||||
>
|
||||
انصراف
|
||||
</button>
|
||||
<button
|
||||
type="submit"
|
||||
disabled={isLoading}
|
||||
className="px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 disabled:opacity-50"
|
||||
>
|
||||
{isLoading ? 'در حال ذخیره...' : 'ذخیره تغییرات'}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user