Skip to content

Commit

Permalink
✨ feat(subscribe): Add unit time
Browse files Browse the repository at this point in the history
  • Loading branch information
web-ppanel committed Dec 20, 2024
1 parent d8b0bd9 commit 39d07ec
Show file tree
Hide file tree
Showing 80 changed files with 553 additions and 165 deletions.
2 changes: 0 additions & 2 deletions apps/admin/app/dashboard/announcement/notice-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
SheetTrigger,
} from '@shadcn/ui/sheet';
import { useTranslations } from 'next-intl';
import { useTheme } from 'next-themes';
import { useEffect, useState } from 'react';

const formSchema = z.object({
Expand All @@ -39,7 +38,6 @@ export default function AnnouncementForm<T extends Record<string, any>>({
title,
}: AnnouncementFormProps<T>) {
const t = useTranslations('announcement');
const { resolvedTheme } = useTheme();
const [open, setOpen] = useState(false);
const form = useForm({
resolver: zodResolver(formSchema),
Expand Down
2 changes: 0 additions & 2 deletions apps/admin/app/dashboard/document/document-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
SheetTrigger,
} from '@shadcn/ui/sheet';
import { useTranslations } from 'next-intl';
import { useTheme } from 'next-themes';
import { useEffect, useState } from 'react';

const formSchema = z.object({
Expand All @@ -41,7 +40,6 @@ export default function DocumentForm<T extends Record<string, any>>({
title,
}: DocumentFormProps<T>) {
const t = useTranslations('document');
const { resolvedTheme } = useTheme();
const [open, setOpen] = useState(false);
const form = useForm({
resolver: zodResolver(formSchema),
Expand Down
45 changes: 37 additions & 8 deletions apps/admin/app/dashboard/subscribe/subscribe-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import {
} from '@shadcn/ui/sheet';
import { useQuery } from '@tanstack/react-query';
import { useTranslations } from 'next-intl';
import { useTheme } from 'next-themes';
import { assign, shake } from 'radash';
import { useEffect, useState } from 'react';

Expand All @@ -53,6 +52,7 @@ const defaultValues = {
discount: [],
server_group: [],
server: [],
unit_time: 'Month',
};

export default function SubscribeForm<T extends Record<string, any>>({
Expand All @@ -63,19 +63,19 @@ export default function SubscribeForm<T extends Record<string, any>>({
title,
}: SubscribeFormProps<T>) {
const t = useTranslations('subscribe');
const { resolvedTheme } = useTheme();

const [open, setOpen] = useState(false);

const formSchema = z.object({
name: z.string(),
description: z.string().optional(),
unit_price: z.number(),
unit_time: z.string().default('Month'),
replacement: z.number().optional(),
discount: z
.array(
z.object({
months: z.number(),
quantity: z.number(),
discount: z.number(),
}),
)
Expand Down Expand Up @@ -135,6 +135,7 @@ export default function SubscribeForm<T extends Record<string, any>>({
},
});

const unit_time = form.watch('unit_time');
return (
<Sheet open={open} onOpenChange={setOpen}>
<SheetTrigger asChild>
Expand Down Expand Up @@ -255,7 +256,7 @@ export default function SubscribeForm<T extends Record<string, any>>({
name='unit_price'
render={({ field }) => (
<FormItem>
<FormLabel>{t('form.unit_price')}</FormLabel>
<FormLabel>{t('form.unitPrice')}</FormLabel>
<FormControl>
<EnhancedInput
type='number'
Expand All @@ -272,6 +273,34 @@ export default function SubscribeForm<T extends Record<string, any>>({
</FormItem>
)}
/>
<FormField
control={form.control}
name='unit_time'
render={({ field }) => (
<FormItem>
<FormLabel>{t('form.unitTime')}</FormLabel>
<FormControl>
<Combobox
placeholder={t('form.selectUnitTime')}
{...field}
onChange={(value) => {
if (value) {
form.setValue(field.name, value);
}
}}
options={[
{ label: t('form.Year'), value: 'Year' },
{ label: t('form.Month'), value: 'Month' },
{ label: t('form.Day'), value: 'Day' },
{ label: t('form.Hour'), value: 'Hour' },
{ label: t('form.Minute'), value: 'Minute' },
]}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name='replacement'
Expand Down Expand Up @@ -436,10 +465,10 @@ export default function SubscribeForm<T extends Record<string, any>>({
<ArrayInput<API.SubscribeDiscount>
fields={[
{
name: 'months',
name: 'quantity',
type: 'number',
min: 1,
suffix: t('form.discountMonths'),
suffix: unit_time && t(`form.${unit_time}`),
},
{
name: 'discount',
Expand All @@ -453,7 +482,7 @@ export default function SubscribeForm<T extends Record<string, any>>({
return {
...data,
price: evaluateWithPrecision(
`${unit_price} * ${data.months} * ${data.discount} / 100`,
`${unit_price} * ${data.quantity} * ${data.discount} / 100`,
),
};
},
Expand All @@ -471,7 +500,7 @@ export default function SubscribeForm<T extends Record<string, any>>({
return {
...data,
discount: evaluateWithPrecision(
`${data.price} / ${data.months} / ${unit_price} * 100`,
`${data.price} / ${data.quantity} / ${unit_price} * 100`,
),
};
},
Expand Down
9 changes: 8 additions & 1 deletion apps/admin/locales/cs-CZ/subscribe.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
"edit": "Upravit",
"editSubscribe": "Upravit odběr",
"form": {
"Day": "Den",
"Hour": "Hodina",
"Minute": "Minuta",
"Month": "Měsíc",
"Year": "Rok",
"cancel": "Zrušit",
"confirm": "Potvrdit",
"description": "Popis",
Expand All @@ -29,12 +34,14 @@
"quota": "Limit nákupu",
"replacement": "Cena za reset (za každý)",
"selectSubscribeGroup": "Vyberte prosím skupinu předplatného",
"selectUnitTime": "Vyberte jednotku času",
"server": "Server",
"serverGroup": "Skupina serverů",
"speedLimit": "Omezení rychlosti (Mbps)",
"subscribeGroup": "Skupina předplatného",
"traffic": "Přenos dat",
"unit_price": "Cena za měsíc"
"unitPrice": "Jednotková cena",
"unitTime": "Jednotka času"
},
"group": {
"actions": "Akce",
Expand Down
9 changes: 8 additions & 1 deletion apps/admin/locales/de-DE/subscribe.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
"edit": "Bearbeiten",
"editSubscribe": "Abonnement bearbeiten",
"form": {
"Day": "Tag",
"Hour": "Stunde",
"Minute": "Minute",
"Month": "Monat",
"Year": "Jahr",
"cancel": "Abbrechen",
"confirm": "Bestätigen",
"description": "Beschreibung",
Expand All @@ -29,12 +34,14 @@
"quota": "Kaufbeschränkung",
"replacement": "Ersatzpreis (pro Mal)",
"selectSubscribeGroup": "Bitte Abonnementgruppe auswählen",
"selectUnitTime": "Bitte wählen Sie eine Zeiteinheit",
"server": "Dienst",
"serverGroup": "Dienstgruppe",
"speedLimit": "Geschwindigkeitsbegrenzung (Mbps)",
"subscribeGroup": "Abonnementgruppe",
"traffic": "Datenvolumen",
"unit_price": "Monatspreis"
"unitPrice": "Einheitspreis",
"unitTime": "Zeiteinheit"
},
"group": {
"actions": "Aktionen",
Expand Down
9 changes: 8 additions & 1 deletion apps/admin/locales/en-US/subscribe.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
"edit": "Edit",
"editSubscribe": "Edit Subscription",
"form": {
"Day": "Day",
"Hour": "Hour",
"Minute": "Minute",
"Month": "Month",
"Year": "Year",
"cancel": "Cancel",
"confirm": "Confirm",
"description": "Description",
Expand All @@ -29,12 +34,14 @@
"quota": "Purchase Limit",
"replacement": "Reset Price (per time)",
"selectSubscribeGroup": "Select Subscription Group",
"selectUnitTime": "Please select a unit of time",
"server": "Server",
"serverGroup": "Server Group",
"speedLimit": "Speed Limit (Mbps)",
"subscribeGroup": "Subscription Group",
"traffic": "Traffic",
"unit_price": "Monthly Price"
"unitPrice": "Unit Price",
"unitTime": "Unit Time"
},
"group": {
"actions": "Actions",
Expand Down
9 changes: 8 additions & 1 deletion apps/admin/locales/es-ES/subscribe.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
"edit": "editar",
"editSubscribe": "Editar suscripción",
"form": {
"Day": "Día",
"Hour": "Hora",
"Minute": "Minuto",
"Month": "Mes",
"Year": "Año",
"cancel": "Cancelar",
"confirm": "Confirmar",
"description": "Descripción",
Expand All @@ -29,12 +34,14 @@
"quota": "Cantidad de compra limitada",
"replacement": "Precio de reposición (cada vez)",
"selectSubscribeGroup": "Por favor, seleccione un grupo de suscripción",
"selectUnitTime": "Por favor, seleccione la unidad de tiempo",
"server": "Servidor",
"serverGroup": "Grupo de servidores",
"speedLimit": "Límite de velocidad (Mbps)",
"subscribeGroup": "Grupo de suscripción",
"traffic": "Tráfico",
"unit_price": "Precio mensual"
"unitPrice": "Precio unitario",
"unitTime": "Unidad de tiempo"
},
"group": {
"actions": "Acciones",
Expand Down
9 changes: 8 additions & 1 deletion apps/admin/locales/es-MX/subscribe.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
"edit": "editar",
"editSubscribe": "Editar suscripción",
"form": {
"Day": "Día",
"Hour": "Hora",
"Minute": "Minuto",
"Month": "Mes",
"Year": "Año",
"cancel": "Cancelar",
"confirm": "Confirmar",
"description": "Descripción",
Expand All @@ -29,12 +34,14 @@
"quota": "Cantidad máxima de compra",
"replacement": "Precio de reposición (cada vez)",
"selectSubscribeGroup": "Por favor seleccione un grupo de suscripción",
"selectUnitTime": "Por favor seleccione la unidad de tiempo",
"server": "Servidor",
"serverGroup": "Grupo de servidores",
"speedLimit": "Límite de velocidad (Mbps)",
"subscribeGroup": "Grupo de suscripción",
"traffic": "Tráfico",
"unit_price": "Precio mensual"
"unitPrice": "Precio unitario",
"unitTime": "Unidad de tiempo"
},
"group": {
"actions": "Acciones",
Expand Down
9 changes: 8 additions & 1 deletion apps/admin/locales/fi-FI/subscribe.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
"edit": "muokkaa",
"editSubscribe": "Muokkaa tilausta",
"form": {
"Day": "Päivä",
"Hour": "Tunti",
"Minute": "Minuutti",
"Month": "Kuukausi",
"Year": "Vuosi",
"cancel": "Peruuta",
"confirm": "Vahvista",
"description": "Kuvaus",
Expand All @@ -29,12 +34,14 @@
"quota": "Ostorajoitus",
"replacement": "Uudelleenhinnan asetus (kerta)",
"selectSubscribeGroup": "Valitse tilausryhmä",
"selectUnitTime": "Valitse aikayksikkö",
"server": "Palvelin",
"serverGroup": "Palvelinryhmä",
"speedLimit": "Nopeusrajoitus (Mbps)",
"subscribeGroup": "Tilausryhmä",
"traffic": "Liikenne",
"unit_price": "Kuukausihinta"
"unitPrice": "Yksikköhinta",
"unitTime": "Aikayksikkö"
},
"group": {
"actions": "Toiminnot",
Expand Down
9 changes: 8 additions & 1 deletion apps/admin/locales/fr-FR/subscribe.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
"edit": "Éditer",
"editSubscribe": "Modifier l'abonnement",
"form": {
"Day": "Jour",
"Hour": "Heure",
"Minute": "Minute",
"Month": "Mois",
"Year": "Année",
"cancel": "Annuler",
"confirm": "Confirmer",
"description": "Description",
Expand All @@ -29,12 +34,14 @@
"quota": "Quantité d'achat limitée",
"replacement": "Prix de réinitialisation (par fois)",
"selectSubscribeGroup": "Veuillez sélectionner un groupe d'abonnement",
"selectUnitTime": "Veuillez sélectionner l'unité de temps",
"server": "Serveur",
"serverGroup": "Groupe de serveurs",
"speedLimit": "Limite de vitesse (Mbps)",
"subscribeGroup": "Groupe d'abonnement",
"traffic": "Trafic",
"unit_price": "Prix mensuel unitaire"
"unitPrice": "Prix unitaire",
"unitTime": "Unité de temps"
},
"group": {
"actions": "Actions",
Expand Down
9 changes: 8 additions & 1 deletion apps/admin/locales/hi-IN/subscribe.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
"edit": "संपादित करें",
"editSubscribe": "संपादन सदस्यता",
"form": {
"Day": "दिन",
"Hour": "घंटा",
"Minute": "मिनट",
"Month": "महीना",
"Year": "वर्ष",
"cancel": "रद्द करें",
"confirm": "पुष्टि करें",
"description": "विवरण",
Expand All @@ -29,12 +34,14 @@
"quota": "खरीद सीमा",
"replacement": "पुनःस्थापना मूल्य (प्रति बार)",
"selectSubscribeGroup": "कृपया सदस्यता समूह चुनें",
"selectUnitTime": "कृपया इकाई समय चुनें",
"server": "सर्वर",
"serverGroup": "सर्वर समूह",
"speedLimit": "गति सीमा (Mbps)",
"subscribeGroup": "सदस्यता समूह",
"traffic": "ट्रैफिक",
"unit_price": "प्रति माह मूल्य"
"unitPrice": "इकाई मूल्य",
"unitTime": "इकाई समय"
},
"group": {
"actions": "क्रियाएँ",
Expand Down
Loading

0 comments on commit 39d07ec

Please sign in to comment.