update view create
This commit is contained in:
parent
3e8e7ae7d7
commit
5af2f6e548
|
|
@ -102,7 +102,14 @@ export default function BidModal({
|
||||||
const { url, max_price, plus_price } = values;
|
const { url, max_price, plus_price } = values;
|
||||||
|
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const result = await createBid({ url, max_price, plus_price } as IBid);
|
|
||||||
|
const metadata = valuesToMetadata(values as IBid & Record<string, any>);
|
||||||
|
const result = await createBid({
|
||||||
|
url,
|
||||||
|
max_price,
|
||||||
|
plus_price,
|
||||||
|
metadata,
|
||||||
|
} as IBid);
|
||||||
|
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
|
||||||
|
|
@ -166,6 +173,27 @@ export default function BidModal({
|
||||||
"early_tracking_seconds_sandbox",
|
"early_tracking_seconds_sandbox",
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if (!values?.metadata) {
|
||||||
|
const mode_key = values.mode_key;
|
||||||
|
|
||||||
|
if (!mode_key) return [];
|
||||||
|
|
||||||
|
const newValues = Object.entries(values)
|
||||||
|
.map(([key, value]) => {
|
||||||
|
if (keys.includes(key)) {
|
||||||
|
return {
|
||||||
|
key_name: key,
|
||||||
|
value,
|
||||||
|
} as IMetadata;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
})
|
||||||
|
.filter((i) => i !== null);
|
||||||
|
|
||||||
|
return newValues;
|
||||||
|
}
|
||||||
|
|
||||||
if (values.metadata.length <= 0) {
|
if (values.metadata.length <= 0) {
|
||||||
return keys.map((item) => {
|
return keys.map((item) => {
|
||||||
return {
|
return {
|
||||||
|
|
@ -203,8 +231,12 @@ export default function BidModal({
|
||||||
}, [props.opened]);
|
}, [props.opened]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const values = mappingValues(["mode_key"]);
|
if (!data && !form.values.mode_key) {
|
||||||
form.setValues(values);
|
form.setValues({ mode_key: "live" });
|
||||||
|
} else {
|
||||||
|
const values = mappingValues(["mode_key"]);
|
||||||
|
form.setValues(values);
|
||||||
|
}
|
||||||
|
|
||||||
prevData.current = data;
|
prevData.current = data;
|
||||||
|
|
||||||
|
|
@ -226,20 +258,18 @@ export default function BidModal({
|
||||||
onSubmit={form.onSubmit(handleSubmit)}
|
onSubmit={form.onSubmit(handleSubmit)}
|
||||||
className="grid grid-cols-2 gap-2.5"
|
className="grid grid-cols-2 gap-2.5"
|
||||||
>
|
>
|
||||||
{!!data && (
|
<Select
|
||||||
<Select
|
className="col-span-2"
|
||||||
className="col-span-2"
|
label="Mode"
|
||||||
label="Mode"
|
data={[
|
||||||
data={[
|
{ label: "Live", value: "live" },
|
||||||
{ label: "Live", value: "live" },
|
{ label: "Sandbox", value: "sandbox" },
|
||||||
{ label: "Sandbox", value: "sandbox" },
|
]}
|
||||||
]}
|
defaultValue="live"
|
||||||
defaultValue="live"
|
checkIconPosition="right"
|
||||||
checkIconPosition="right"
|
allowDeselect={false}
|
||||||
allowDeselect={false}
|
{...form.getInputProps("mode_key")}
|
||||||
{...form.getInputProps("mode_key")}
|
/>
|
||||||
/>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{data && data.name && (
|
{data && data.name && (
|
||||||
<TextInput
|
<TextInput
|
||||||
|
|
@ -274,39 +304,35 @@ export default function BidModal({
|
||||||
{...form.getInputProps("quantity")}
|
{...form.getInputProps("quantity")}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{!!data && (
|
<NumberInput
|
||||||
<NumberInput
|
description="Note: that only integer minutes are accepted."
|
||||||
description="Note: that only integer minutes are accepted."
|
className="col-span-1"
|
||||||
className="col-span-1"
|
size="sm"
|
||||||
size="sm"
|
label={`Arrival offset seconds (${formatTimeFromMinutes(
|
||||||
label={`Arrival offset seconds (${formatTimeFromMinutes(
|
form.getValues()[
|
||||||
form.getValues()[
|
|
||||||
`arrival_offset_seconds_${form.getValues()["mode_key"]}`
|
|
||||||
] / 60
|
|
||||||
)})`}
|
|
||||||
placeholder="msg: 300"
|
|
||||||
{...form.getInputProps(
|
|
||||||
`arrival_offset_seconds_${form.getValues()["mode_key"]}`
|
`arrival_offset_seconds_${form.getValues()["mode_key"]}`
|
||||||
)}
|
] / 60
|
||||||
/>
|
)})`}
|
||||||
)}
|
placeholder="msg: 300"
|
||||||
|
{...form.getInputProps(
|
||||||
|
`arrival_offset_seconds_${form.getValues()["mode_key"]}`
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
{!!data && (
|
<NumberInput
|
||||||
<NumberInput
|
description="Note: that only integer minutes are accepted."
|
||||||
description="Note: that only integer minutes are accepted."
|
className="col-span-1"
|
||||||
className="col-span-1"
|
size="sm"
|
||||||
size="sm"
|
label={`Early tracking seconds (${formatTimeFromMinutes(
|
||||||
label={`Early tracking seconds (${formatTimeFromMinutes(
|
form.getValues()[
|
||||||
form.getValues()[
|
|
||||||
`early_tracking_seconds_${form.getValues()["mode_key"]}`
|
|
||||||
] / 60
|
|
||||||
)})`}
|
|
||||||
placeholder="msg: 600"
|
|
||||||
{...form.getInputProps(
|
|
||||||
`early_tracking_seconds_${form.getValues()["mode_key"]}`
|
`early_tracking_seconds_${form.getValues()["mode_key"]}`
|
||||||
)}
|
] / 60
|
||||||
/>
|
)})`}
|
||||||
)}
|
placeholder="msg: 600"
|
||||||
|
{...form.getInputProps(
|
||||||
|
`early_tracking_seconds_${form.getValues()["mode_key"]}`
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
// disabled={_.isEqual(form.values, prevData.current)}
|
// disabled={_.isEqual(form.values, prevData.current)}
|
||||||
|
|
|
||||||
|
|
@ -95,10 +95,6 @@ export default function ResponseDemoModal({
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
console.log({ responseDemo });
|
|
||||||
}, [responseDemo]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
classNames={{
|
classNames={{
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import { Optional } from '@nestjs/common';
|
import { Optional } from '@nestjs/common';
|
||||||
import {
|
import {
|
||||||
|
IsArray,
|
||||||
IsBoolean,
|
IsBoolean,
|
||||||
IsNumber,
|
IsNumber,
|
||||||
IsOptional,
|
IsOptional,
|
||||||
|
|
@ -21,4 +22,8 @@ export class CreateBidDto {
|
||||||
@IsNumber()
|
@IsNumber()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
plus_price: number;
|
plus_price: number;
|
||||||
|
|
||||||
|
@IsArray()
|
||||||
|
@IsOptional()
|
||||||
|
metadata: Record<string, any>[];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -125,7 +125,27 @@ export class BidsService {
|
||||||
|
|
||||||
const webBid = await this.webBidsService.createByUrl(data.url);
|
const webBid = await this.webBidsService.createByUrl(data.url);
|
||||||
|
|
||||||
const metadata = BidMetadata.DEFAULT_META_DATA(webBid);
|
let metadata = BidMetadata.DEFAULT_META_DATA(webBid);
|
||||||
|
|
||||||
|
if (data.metadata) {
|
||||||
|
metadata = metadata.map((item) => {
|
||||||
|
const reqData = data.metadata.find(
|
||||||
|
(i) => i?.key_name === item.key_name,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!reqData) return { ...item };
|
||||||
|
|
||||||
|
return {
|
||||||
|
...item,
|
||||||
|
value:
|
||||||
|
item.key_name === BidMetadata.MODE_KEY
|
||||||
|
? JSON.stringify(reqData.value)
|
||||||
|
: reqData.value <= 0
|
||||||
|
? item.value
|
||||||
|
: String(reqData.value),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const result = await this.bidsRepo.save({
|
const result = await this.bidsRepo.save({
|
||||||
...data,
|
...data,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue