mirror of
https://github.com/chillpadclub/bedolaga-cabinet.git
synced 2026-07-28 09:33:46 +00:00
fix(tariffs): отправлять пустые промогруппы и описание при редактировании тарифа
This commit is contained in:
@@ -4,12 +4,12 @@ import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
|||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import {
|
import {
|
||||||
tariffsApi,
|
tariffsApi,
|
||||||
TariffDetail,
|
type TariffDetail,
|
||||||
TariffCreateRequest,
|
type TariffCreateRequest,
|
||||||
TariffUpdateRequest,
|
type TariffUpdateRequest,
|
||||||
PeriodPrice,
|
type PeriodPrice,
|
||||||
ServerInfo,
|
type ServerInfo,
|
||||||
ExternalSquadInfo,
|
type ExternalSquadInfo,
|
||||||
} from '../api/tariffs';
|
} from '../api/tariffs';
|
||||||
import { AdminBackButton } from '../components/admin';
|
import { AdminBackButton } from '../components/admin';
|
||||||
import { createNumberInputHandler, toNumber } from '../utils/inputHelpers';
|
import { createNumberInputHandler, toNumber } from '../utils/inputHelpers';
|
||||||
@@ -153,9 +153,12 @@ export default function AdminTariffCreate() {
|
|||||||
const handleSubmit = () => {
|
const handleSubmit = () => {
|
||||||
const isDaily = tariffType === 'daily';
|
const isDaily = tariffType === 'daily';
|
||||||
|
|
||||||
|
// PATCH applies a field only when it is present in the payload, so empty
|
||||||
|
// values ('' / []) must still be sent when editing — omitting them makes
|
||||||
|
// clearing the description or unchecking all promo groups impossible.
|
||||||
const data: TariffCreateRequest | TariffUpdateRequest = {
|
const data: TariffCreateRequest | TariffUpdateRequest = {
|
||||||
name,
|
name,
|
||||||
description: description || undefined,
|
description: isEdit ? description : description || undefined,
|
||||||
is_active: isActive,
|
is_active: isActive,
|
||||||
show_in_gift: showInGift,
|
show_in_gift: showInGift,
|
||||||
traffic_limit_gb: toNumber(trafficLimitGb, 100),
|
traffic_limit_gb: toNumber(trafficLimitGb, 100),
|
||||||
@@ -167,7 +170,7 @@ export default function AdminTariffCreate() {
|
|||||||
period_prices: isDaily ? [] : periodPrices.filter((p) => p.price_kopeks >= 0),
|
period_prices: isDaily ? [] : periodPrices.filter((p) => p.price_kopeks >= 0),
|
||||||
allowed_squads: selectedSquads,
|
allowed_squads: selectedSquads,
|
||||||
external_squad_uuid: selectedExternalSquad || null,
|
external_squad_uuid: selectedExternalSquad || null,
|
||||||
promo_group_ids: selectedPromoGroups.length > 0 ? selectedPromoGroups : undefined,
|
promo_group_ids: selectedPromoGroups,
|
||||||
traffic_topup_enabled: trafficTopupEnabled,
|
traffic_topup_enabled: trafficTopupEnabled,
|
||||||
traffic_topup_packages: trafficTopupPackages,
|
traffic_topup_packages: trafficTopupPackages,
|
||||||
max_topup_traffic_gb: toNumber(maxTopupTrafficGb),
|
max_topup_traffic_gb: toNumber(maxTopupTrafficGb),
|
||||||
@@ -600,7 +603,7 @@ export default function AdminTariffCreate() {
|
|||||||
setEditingPeriodPrices((prev) => ({ ...prev, [period.days]: val }));
|
setEditingPeriodPrices((prev) => ({ ...prev, [period.days]: val }));
|
||||||
if (val !== '') {
|
if (val !== '') {
|
||||||
const num = parseFloat(val);
|
const num = parseFloat(val);
|
||||||
if (!isNaN(num)) {
|
if (!Number.isNaN(num)) {
|
||||||
updatePeriodPrice(period.days, Math.max(0, num));
|
updatePeriodPrice(period.days, Math.max(0, num));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -938,7 +941,7 @@ export default function AdminTariffCreate() {
|
|||||||
setEditingPackagePrices((prev) => ({ ...prev, [gb]: val }));
|
setEditingPackagePrices((prev) => ({ ...prev, [gb]: val }));
|
||||||
if (val !== '') {
|
if (val !== '') {
|
||||||
const num = parseFloat(val);
|
const num = parseFloat(val);
|
||||||
if (!isNaN(num)) {
|
if (!Number.isNaN(num)) {
|
||||||
setTrafficTopupPackages((prev) => ({
|
setTrafficTopupPackages((prev) => ({
|
||||||
...prev,
|
...prev,
|
||||||
[gb]: Math.max(0, num) * 100,
|
[gb]: Math.max(0, num) * 100,
|
||||||
|
|||||||
Reference in New Issue
Block a user