Merge branch 'dev' into 'main'
минимальные и максимальные значения для кастомного тарифа See merge request frontend/marketplace!92
This commit is contained in:
commit
acd76168f0
@ -2,15 +2,24 @@ import { useState } from "react"
|
||||
import { InputAdornment, TextField, Typography, useTheme } from "@mui/material"
|
||||
|
||||
import type { ChangeEvent } from "react"
|
||||
import {Privilege} from "@frontend/kitui"
|
||||
|
||||
interface Props {
|
||||
id: string;
|
||||
value: number;
|
||||
adornmentText: string;
|
||||
privilege: Privilege;
|
||||
onChange: (value: number) => void;
|
||||
}
|
||||
|
||||
export default function NumberInputWithUnitAdornment({ id, value, adornmentText, onChange }: Props) {
|
||||
const sliderSettingsByType = {
|
||||
день: { max: 365, min: 30 },
|
||||
шаблон: { max: 5000, min: 100 },
|
||||
МБ: { max: 5000, min: 100 },
|
||||
заявка: { max: 5000, min: 100 }
|
||||
}
|
||||
|
||||
export default function NumberInputWithUnitAdornment({ id, value, adornmentText, privilege, onChange }: Props) {
|
||||
const theme = useTheme()
|
||||
const [changed, setChanged] = useState<boolean>(false)
|
||||
|
||||
@ -20,7 +29,7 @@ export default function NumberInputWithUnitAdornment({ id, value, adornmentText,
|
||||
size="small"
|
||||
placeholder="Введите вручную"
|
||||
id={id}
|
||||
value={changed ? (value !== 0 ? value : "") : ""}
|
||||
value={changed ? (value !== sliderSettingsByType[privilege.value]?.min ? value : sliderSettingsByType[privilege.value]?.min) : ""}
|
||||
onChange={({ target }: ChangeEvent<HTMLInputElement>) => {
|
||||
if (!changed) {
|
||||
setChanged(true)
|
||||
@ -34,7 +43,7 @@ export default function NumberInputWithUnitAdornment({ id, value, adornmentText,
|
||||
|
||||
|
||||
if (!isFinite(newNumber) || newNumber < 0) {
|
||||
onChange(0)
|
||||
onChange(sliderSettingsByType[privilege.value]?.min)
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -44,6 +44,7 @@ function TariffConstructor() {
|
||||
>
|
||||
{Object.entries(customTariffs).filter(([serviceKey]) => serviceKey === "squiz").map(([serviceKey, privileges], index) => {
|
||||
console.log("serviceKey ",serviceKey)
|
||||
console.log(Object.entries(customTariffs))
|
||||
return <Box key={index}>
|
||||
<Box
|
||||
sx={{
|
||||
|
@ -16,8 +16,9 @@ const sliderSettingsByType = {
|
||||
день: { max: 365, min: 30 },
|
||||
шаблон: { max: 5000, min: 100 },
|
||||
МБ: { max: 5000, min: 100 },
|
||||
заявка: { max: 5000, min: 100 }
|
||||
}
|
||||
type PrivilegeName = "день" | "шаблон" | "МБ"
|
||||
type PrivilegeName = "день" | "шаблон" | "МБ" | "заявка"
|
||||
|
||||
interface Props {
|
||||
privilege: Privilege;
|
||||
@ -26,10 +27,10 @@ interface Props {
|
||||
export default function TariffPrivilegeSlider({ privilege }: Props) {
|
||||
const theme = useTheme()
|
||||
const upMd = useMediaQuery(theme.breakpoints.up("md"))
|
||||
const userValue = useCustomTariffsStore((state) => state.userValuesMap[privilege.serviceKey]?.[privilege._id]) ?? 0
|
||||
const userValue = useCustomTariffsStore((state) => state.userValuesMap[privilege.serviceKey]?.[privilege._id]) ?? sliderSettingsByType[privilege.value]?.min
|
||||
const discounts = useDiscountStore((state) => state.discounts)
|
||||
const currentCartTotal = useCartStore((state) => state.cart.priceAfterDiscounts)
|
||||
const purchasesAmount = useUserStore((state) => state.userAccount?.wallet.spent) ?? 0
|
||||
const purchasesAmount = useUserStore((state) => state.userAccount?.wallet.spent) ?? sliderSettingsByType[privilege.value]?.min
|
||||
const isUserNko = useUserStore(state => state.userAccount?.status) === "nko"
|
||||
const [value, setValue] = useState<number>(userValue)
|
||||
const throttledValue = useThrottle(value, 200)
|
||||
@ -67,7 +68,7 @@ export default function TariffPrivilegeSlider({ privilege }: Props) {
|
||||
|
||||
|
||||
const setNotSmallNumber = useDebouncedCallback(() => {
|
||||
if (value === 0) return
|
||||
if (value === sliderSettingsByType[privilege.value]?.min) return
|
||||
if (Number(value) < Number(sliderSettingsByType[privilege.value]?.min)) {
|
||||
setValue(sliderSettingsByType[privilege.value]?.min)
|
||||
}
|
||||
@ -99,6 +100,7 @@ export default function TariffPrivilegeSlider({ privilege }: Props) {
|
||||
<NumberInputWithUnitAdornment
|
||||
id={"privilege_input_" + privilege._id}
|
||||
value={value}
|
||||
privilege={privilege}
|
||||
adornmentText={getDeclension(0, privilege.value)}
|
||||
onChange={(value) => {
|
||||
setValue(value)
|
||||
@ -152,7 +154,7 @@ export default function TariffPrivilegeSlider({ privilege }: Props) {
|
||||
</Box>
|
||||
<CustomSlider
|
||||
value={value}
|
||||
min={0}
|
||||
min={sliderSettingsByType[privilege.value]?.min }
|
||||
max={sliderSettingsByType[privilege.value]?.max || 100}
|
||||
onChange={handleSliderChange(privilege.value)}
|
||||
/>
|
||||
|
Loading…
Reference in New Issue
Block a user