gitscope
← marzneshin / Diff · 39380ee → 39380ee
Changes 39380ee..39380ee
Patch commit
diff --git a/dashboard/public/locales/kur.json b/dashboard/public/locales/kur.json
index 3a079b1..acc5b5e 100644
--- a/dashboard/public/locales/kur.json
+++ b/dashboard/public/locales/kur.json
@@ -10,7 +10,7 @@
"password": "Têperrewişe",
"inbounds": "înbawendkan",
"submit": "Nardin",
- "login": "Çûnejûrew",
+ "login": "Çûnejûrewe",
"edit": "Desitkarîkirdn",
"actions": "Fermankan",
"settings": "Sazkarîyekan",
@@ -95,7 +95,7 @@
"users": {
"data_limit": "Sinûrî data",
"used_traffic": "Traffic bekarhêndiraw",
- "data_limit_reset_strategy": "Sêwazî sirrinewey sinûrî data",
+ "data_limit_reset_strategy": "Şêwazî sirrinewey sinûrî data",
"online_at": "Online Le",
"expire_date": "Katî beserçûn",
"unlimited": "Bêsinûr",
diff --git a/dashboard/src/features/users/components/services-card.tsx b/dashboard/src/features/users/components/services-card.tsx
index c0d9e5b..e941cc3 100644
--- a/dashboard/src/features/users/components/services-card.tsx
+++ b/dashboard/src/features/users/components/services-card.tsx
@@ -20,7 +20,7 @@ export const ServiceCard: FC<ServiceCardProps> = (
) => {
if (service.users && service.inbounds) {
return (
- <div className="w-full border rounded-md p-2 flex justify-between flex-row items-center">
+ <div className="w-full flex justify-between flex-row items-center">
<Label>{service.name}</Label>
<div className="flex flex-row items-center gap-1">
<ServiceProperty Icon={UserIcon} amount={service.users.length} />
diff --git a/dashboard/src/features/users/dialogs/mutation/fields/data-limit-reset-strategy.tsx b/dashboard/src/features/users/dialogs/mutation/fields/data-limit-reset-strategy.tsx
index 6c02926..89512ab 100644
--- a/dashboard/src/features/users/dialogs/mutation/fields/data-limit-reset-strategy.tsx
+++ b/dashboard/src/features/users/dialogs/mutation/fields/data-limit-reset-strategy.tsx
@@ -25,7 +25,7 @@ export const DataLimitResetStrategyField: FC<DataLimitResetStrategyFieldProps> =
name="data_limit_reset_strategy"
render={({ field }) => (
<FormItem className="w-full">
- <FormLabel>{t('Data Limit Reset Strategy')}</FormLabel>
+ <FormLabel>{t('page.users.data_limit_reset_strategy')}</FormLabel>
<Select onValueChange={field.onChange} defaultValue={field.value}>
<FormControl>
<SelectTrigger>
diff --git a/dashboard/src/features/users/dialogs/mutation/fields/services.tsx b/dashboard/src/features/users/dialogs/mutation/fields/services.tsx
index a526351..bd2b341 100644
--- a/dashboard/src/features/users/dialogs/mutation/fields/services.tsx
+++ b/dashboard/src/features/users/dialogs/mutation/fields/services.tsx
@@ -1,14 +1,15 @@
import {
- FormControl,
- FormField,
- FormItem,
- FormLabel,
- FormMessage,
- ScrollArea,
- Toggle
+ Checkbox,
+ FormControl,
+ FormField,
+ FormItem,
+ FormLabel,
+ FormMessage,
+ ScrollArea,
} from '@marzneshin/components';
import { useServicesQuery } from '@marzneshin/features/services';
import { ServiceCard } from '@marzneshin/features/users';
+import { cn } from '@marzneshin/utils';
import { FC } from 'react'
import { useFormContext } from 'react-hook-form';
import { useTranslation } from 'react-i18next';
@@ -16,46 +17,53 @@ import { useTranslation } from 'react-i18next';
interface ServicesFieldProps { }
export const ServicesField: FC<ServicesFieldProps> = () => {
- const form = useFormContext();
- const { data } = useServicesQuery({ page: 1, size: 100 });
- const { t } = useTranslation();
+ const form = useFormContext();
+ const { data } = useServicesQuery({ page: 1, size: 100 });
+ const { t } = useTranslation();
- return (
- <FormItem>
- <FormLabel>{t('services')}</FormLabel>
- <ScrollArea className="flex flex-col justify-start px-1 h-[22rem]">
- {data.entity.map(service => (
- <FormField
+ console.log(form.getValues().services)
+ return (
+ <FormField
control={form.control}
- name={`services`}
- render={({ field }) => (
- <FormItem>
- <FormControl>
- <Toggle
- key={service.id}
- value={String(service.id)}
- pressed={field.value?.includes(service.id)}
- onPressedChange={(checked) => {
- return checked
- ? field.onChange([...field.value, service.id])
- : field.onChange(
- field.value?.filter(
- (value: number) => value !== service.id
- )
- )
- }}
- {...form.register(`services.${service.id}`, { shouldUnregister: true })}
- className="px-0 mb-1 w-full"
- >
- <ServiceCard service={service} />
- </Toggle>
- </FormControl>
- <FormMessage />
- </FormItem>
+ name="services"
+ render={() => (
+ <FormItem>
+ <FormLabel>{t('services')}</FormLabel>
+ <ScrollArea className="flex flex-col justify-start px-1 h-[22rem]">
+ {data.entity.map(service => (
+ <FormField
+ control={form.control}
+ name='services'
+ render={({ field }) => (
+ <FormItem key={service.id}>
+ <FormControl>
+ <div
+ className={cn("flex mb-2 flex-row gap-2 items-center p-3 rounded-md border", { "bg-secondary": field.value?.includes(service.id) })}>
+ <Checkbox
+ checked={field.value?.includes(service.id)}
+ onCheckedChange={(checked) => {
+ return checked
+ ? field.onChange([...field.value, service.id])
+ : field.onChange(
+ field.value?.filter(
+ (value: number) => value !== service.id
+ )
+ )
+ }}
+ />
+ <FormLabel className="flex flex-row justify-between items-center w-full">
+ <ServiceCard service={service} />
+ </FormLabel>
+ </div>
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ ))}
+ </ScrollArea>
+ </FormItem>
)}
- />
- ))}
- </ScrollArea>
- </FormItem>
- );
+ />
+ );
};
diff --git a/dashboard/src/features/users/dialogs/mutation/index.tsx b/dashboard/src/features/users/dialogs/mutation/index.tsx
index ed4337a..72f14dc 100644
--- a/dashboard/src/features/users/dialogs/mutation/index.tsx
+++ b/dashboard/src/features/users/dialogs/mutation/index.tsx
@@ -79,11 +79,20 @@ export const UsersMutationDialog: FC<UsersMutationDialogProps> = ({
}
}, [selectedDataLimitTab, form]);
-
+ const getUserExpirationMethod = useCallback((entity: UserMutationType) => {
+ if (entity.status === "on_hold")
+ return 'onhold'
+ else if (entity.expire !== undefined)
+ return 'determined'
+ else
+ return 'unlimited'
+ }, [])
+ const defaultExpirationMethodTab = entity?.username ? getUserExpirationMethod(entity) : 'determined'
const [
selectedExpirationMethodTab,
setSelectedExpirationMethodTab
- ] = useState<'determined' | 'onhold' | 'unlimited' | string>('determined');
+ ] = useState<'determined' | 'onhold' | 'unlimited' | string>(defaultExpirationMethodTab);
+
useEffect(() => {
form.setValue("status", "active")
if (selectedExpirationMethodTab === 'onhold') {
@@ -146,7 +155,7 @@ export const UsersMutationDialog: FC<UsersMutationDialogProps> = ({
<FormLabel>
{t('page.users.expire_method')}
</FormLabel>
- <Tabs defaultValue="determined" onValueChange={setSelectedExpirationMethodTab} className="mt-2 w-full">
+ <Tabs defaultValue={defaultExpirationMethodTab} onValueChange={setSelectedExpirationMethodTab} className="mt-2 w-full">
<TabsList className="flex flex-row items-center p-1 w-full rounded-md bg-accent">
<TabsTrigger
className="w-full"