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;
|
||||
|
||||
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);
|
||||
|
||||
|
|
@ -166,6 +173,27 @@ export default function BidModal({
|
|||
"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) {
|
||||
return keys.map((item) => {
|
||||
return {
|
||||
|
|
@ -203,8 +231,12 @@ export default function BidModal({
|
|||
}, [props.opened]);
|
||||
|
||||
useEffect(() => {
|
||||
const values = mappingValues(["mode_key"]);
|
||||
form.setValues(values);
|
||||
if (!data && !form.values.mode_key) {
|
||||
form.setValues({ mode_key: "live" });
|
||||
} else {
|
||||
const values = mappingValues(["mode_key"]);
|
||||
form.setValues(values);
|
||||
}
|
||||
|
||||
prevData.current = data;
|
||||
|
||||
|
|
@ -226,20 +258,18 @@ export default function BidModal({
|
|||
onSubmit={form.onSubmit(handleSubmit)}
|
||||
className="grid grid-cols-2 gap-2.5"
|
||||
>
|
||||
{!!data && (
|
||||
<Select
|
||||
className="col-span-2"
|
||||
label="Mode"
|
||||
data={[
|
||||
{ label: "Live", value: "live" },
|
||||
{ label: "Sandbox", value: "sandbox" },
|
||||
]}
|
||||
defaultValue="live"
|
||||
checkIconPosition="right"
|
||||
allowDeselect={false}
|
||||
{...form.getInputProps("mode_key")}
|
||||
/>
|
||||
)}
|
||||
<Select
|
||||
className="col-span-2"
|
||||
label="Mode"
|
||||
data={[
|
||||
{ label: "Live", value: "live" },
|
||||
{ label: "Sandbox", value: "sandbox" },
|
||||
]}
|
||||
defaultValue="live"
|
||||
checkIconPosition="right"
|
||||
allowDeselect={false}
|
||||
{...form.getInputProps("mode_key")}
|
||||
/>
|
||||
|
||||
{data && data.name && (
|
||||
<TextInput
|
||||
|
|
@ -274,39 +304,35 @@ export default function BidModal({
|
|||
{...form.getInputProps("quantity")}
|
||||
/>
|
||||
|
||||
{!!data && (
|
||||
<NumberInput
|
||||
description="Note: that only integer minutes are accepted."
|
||||
className="col-span-1"
|
||||
size="sm"
|
||||
label={`Arrival offset seconds (${formatTimeFromMinutes(
|
||||
form.getValues()[
|
||||
`arrival_offset_seconds_${form.getValues()["mode_key"]}`
|
||||
] / 60
|
||||
)})`}
|
||||
placeholder="msg: 300"
|
||||
{...form.getInputProps(
|
||||
<NumberInput
|
||||
description="Note: that only integer minutes are accepted."
|
||||
className="col-span-1"
|
||||
size="sm"
|
||||
label={`Arrival offset seconds (${formatTimeFromMinutes(
|
||||
form.getValues()[
|
||||
`arrival_offset_seconds_${form.getValues()["mode_key"]}`
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
] / 60
|
||||
)})`}
|
||||
placeholder="msg: 300"
|
||||
{...form.getInputProps(
|
||||
`arrival_offset_seconds_${form.getValues()["mode_key"]}`
|
||||
)}
|
||||
/>
|
||||
|
||||
{!!data && (
|
||||
<NumberInput
|
||||
description="Note: that only integer minutes are accepted."
|
||||
className="col-span-1"
|
||||
size="sm"
|
||||
label={`Early tracking seconds (${formatTimeFromMinutes(
|
||||
form.getValues()[
|
||||
`early_tracking_seconds_${form.getValues()["mode_key"]}`
|
||||
] / 60
|
||||
)})`}
|
||||
placeholder="msg: 600"
|
||||
{...form.getInputProps(
|
||||
<NumberInput
|
||||
description="Note: that only integer minutes are accepted."
|
||||
className="col-span-1"
|
||||
size="sm"
|
||||
label={`Early tracking seconds (${formatTimeFromMinutes(
|
||||
form.getValues()[
|
||||
`early_tracking_seconds_${form.getValues()["mode_key"]}`
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
] / 60
|
||||
)})`}
|
||||
placeholder="msg: 600"
|
||||
{...form.getInputProps(
|
||||
`early_tracking_seconds_${form.getValues()["mode_key"]}`
|
||||
)}
|
||||
/>
|
||||
|
||||
<Button
|
||||
// disabled={_.isEqual(form.values, prevData.current)}
|
||||
|
|
|
|||
|
|
@ -95,10 +95,6 @@ export default function ResponseDemoModal({
|
|||
});
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
console.log({ responseDemo });
|
||||
}, [responseDemo]);
|
||||
|
||||
return (
|
||||
<Modal
|
||||
classNames={{
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { Optional } from '@nestjs/common';
|
||||
import {
|
||||
IsArray,
|
||||
IsBoolean,
|
||||
IsNumber,
|
||||
IsOptional,
|
||||
|
|
@ -21,4 +22,8 @@ export class CreateBidDto {
|
|||
@IsNumber()
|
||||
@IsOptional()
|
||||
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 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({
|
||||
...data,
|
||||
|
|
|
|||
Loading…
Reference in New Issue