feat: ym sync
This commit is contained in:
@@ -281,6 +281,8 @@ export type { GetTimeTrackingRecordsResponse } from './models/GetTimeTrackingRec
|
||||
export type { GetTransactionTagsResponse } from './models/GetTransactionTagsResponse';
|
||||
export type { GetWorkShiftsPlanningDataRequest } from './models/GetWorkShiftsPlanningDataRequest';
|
||||
export type { GetWorkShiftsResponse } from './models/GetWorkShiftsResponse';
|
||||
export type { GetYandexMarketCampaignsRequest } from './models/GetYandexMarketCampaignsRequest';
|
||||
export type { GetYandexMarketCampaignsResponse } from './models/GetYandexMarketCampaignsResponse';
|
||||
export type { GroupBillRequestSchema } from './models/GroupBillRequestSchema';
|
||||
export type { HTTPValidationError } from './models/HTTPValidationError';
|
||||
export type { LoadMessagesResponse } from './models/LoadMessagesResponse';
|
||||
@@ -449,6 +451,7 @@ export type { UserUpdate } from './models/UserUpdate';
|
||||
export type { ValidationError } from './models/ValidationError';
|
||||
export type { WorkShiftRowSchema } from './models/WorkShiftRowSchema';
|
||||
export type { WorkShiftSchema } from './models/WorkShiftSchema';
|
||||
export type { YandexMarketCampaignSchema } from './models/YandexMarketCampaignSchema';
|
||||
|
||||
export { AttributeService } from './services/AttributeService';
|
||||
export { AuthService } from './services/AuthService';
|
||||
|
||||
8
src/client/models/GetYandexMarketCampaignsRequest.ts
Normal file
8
src/client/models/GetYandexMarketCampaignsRequest.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
/* generated using openapi-typescript-codegen -- do not edit */
|
||||
/* istanbul ignore file */
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
export type GetYandexMarketCampaignsRequest = {
|
||||
apiKey: string;
|
||||
};
|
||||
|
||||
9
src/client/models/GetYandexMarketCampaignsResponse.ts
Normal file
9
src/client/models/GetYandexMarketCampaignsResponse.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
/* generated using openapi-typescript-codegen -- do not edit */
|
||||
/* istanbul ignore file */
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
import type { YandexMarketCampaignSchema } from './YandexMarketCampaignSchema';
|
||||
export type GetYandexMarketCampaignsResponse = {
|
||||
campaigns: Array<YandexMarketCampaignSchema>;
|
||||
};
|
||||
|
||||
9
src/client/models/YandexMarketCampaignSchema.ts
Normal file
9
src/client/models/YandexMarketCampaignSchema.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
/* generated using openapi-typescript-codegen -- do not edit */
|
||||
/* istanbul ignore file */
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
export type YandexMarketCampaignSchema = {
|
||||
id: number;
|
||||
name: string;
|
||||
};
|
||||
|
||||
@@ -9,6 +9,8 @@ import type { DeleteMarketplaceResponse } from '../models/DeleteMarketplaceRespo
|
||||
import type { GetAllBaseMarketplacesResponse } from '../models/GetAllBaseMarketplacesResponse';
|
||||
import type { GetClientMarketplacesRequest } from '../models/GetClientMarketplacesRequest';
|
||||
import type { GetClientMarketplacesResponse } from '../models/GetClientMarketplacesResponse';
|
||||
import type { GetYandexMarketCampaignsRequest } from '../models/GetYandexMarketCampaignsRequest';
|
||||
import type { GetYandexMarketCampaignsResponse } from '../models/GetYandexMarketCampaignsResponse';
|
||||
import type { UpdateMarketplaceRequest } from '../models/UpdateMarketplaceRequest';
|
||||
import type { UpdateMarketplaceResponse } from '../models/UpdateMarketplaceResponse';
|
||||
import type { CancelablePromise } from '../core/CancelablePromise';
|
||||
@@ -106,4 +108,24 @@ export class MarketplaceService {
|
||||
},
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Get Yandex Market Campaigns
|
||||
* @returns GetYandexMarketCampaignsResponse Successful Response
|
||||
* @throws ApiError
|
||||
*/
|
||||
public static getYandexMarketCampaigns({
|
||||
requestBody,
|
||||
}: {
|
||||
requestBody: GetYandexMarketCampaignsRequest,
|
||||
}): CancelablePromise<GetYandexMarketCampaignsResponse> {
|
||||
return __request(OpenAPI, {
|
||||
method: 'POST',
|
||||
url: '/marketplace/yandex-market/get-campaigns',
|
||||
body: requestBody,
|
||||
mediaType: 'application/json',
|
||||
errors: {
|
||||
422: `Validation Error`,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
import { Loader, Select, SelectProps } from "@mantine/core";
|
||||
import {
|
||||
MarketplaceAuthData,
|
||||
} from "../../../pages/MarketplacesPage/modals/MarketplaceFormModal/MarketplaceFormModal.tsx";
|
||||
import { omit } from "lodash";
|
||||
import { useEffect, useState } from "react";
|
||||
import { MarketplaceService, YandexMarketCampaignSchema } from "../../../client";
|
||||
|
||||
type RestProps = {
|
||||
authData: MarketplaceAuthData;
|
||||
onChange(value: YandexMarketCampaignSchema): void;
|
||||
value?: string;
|
||||
|
||||
}
|
||||
type Props = Omit<SelectProps, "data" | "value" | "onChange"> & RestProps;
|
||||
|
||||
const YandexMarketCampaignSelect = (props: Props) => {
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
|
||||
const [data, setData] = useState<{ label: string, value: string }[]>([]);
|
||||
const restProps = omit(props, ["authData", "onChange", "value"]);
|
||||
const { authData } = props;
|
||||
const fetchData = async () => {
|
||||
const apiKey = authData["Api-Key"];
|
||||
if (!apiKey || !apiKey.startsWith("ACMA")) return;
|
||||
setIsLoading(true);
|
||||
MarketplaceService.getYandexMarketCampaigns({ requestBody: { apiKey: apiKey } }).then(response => {
|
||||
const campaigns = response.campaigns;
|
||||
const data = campaigns.map((campaign) => ({
|
||||
value: campaign.id.toString(),
|
||||
label: campaign.name,
|
||||
}));
|
||||
setData(data);
|
||||
setIsLoading(false);
|
||||
});
|
||||
};
|
||||
const onChange = (value: string | null) => {
|
||||
const selected = data.find(item => item.value === value);
|
||||
if (selected) {
|
||||
props.onChange({ id: parseInt(selected.value), name: selected.label });
|
||||
}
|
||||
};
|
||||
useEffect(() => {
|
||||
fetchData();
|
||||
}, [authData["Api-Key"]]);
|
||||
return (
|
||||
<Select
|
||||
{...restProps}
|
||||
disabled={isLoading}
|
||||
rightSection={isLoading && <Loader size={16} />}
|
||||
value={props.value?.toString()}
|
||||
onChange={onChange}
|
||||
data={data}
|
||||
label="Магазин"
|
||||
placeholder="Выберите магазин"
|
||||
searchable
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default YandexMarketCampaignSelect;
|
||||
@@ -3,19 +3,23 @@ import { BaseFormInputProps } from "../../../../types/utils.ts";
|
||||
import { FC } from "react";
|
||||
import { BaseMarketplaceSchema } from "../../../../client";
|
||||
import { BaseMarketplaceType } from "../../../../shared/enums/BaseMarketplaceType.ts";
|
||||
import { MarketplaceAuthData } from "./MarketplaceFormModal.tsx";
|
||||
import YandexMarketCampaignSelect
|
||||
from "../../../../components/Selects/YandexMarketCampaignSelect/YandexMarketCampaignSelect.tsx";
|
||||
import { omit } from "lodash";
|
||||
|
||||
type RestProps = {
|
||||
baseMarketplace: BaseMarketplaceSchema;
|
||||
};
|
||||
type Props = BaseFormInputProps<Record<string, string>> & RestProps;
|
||||
type Props = BaseFormInputProps<MarketplaceAuthData> & RestProps;
|
||||
|
||||
const MarketplaceAuthDataInput: FC<Props> = (props: Props) => {
|
||||
console.log(props.baseMarketplace);
|
||||
const restProps = omit(props, ["baseMarketplace"]);
|
||||
const getWildberriesInputs = () => {
|
||||
// return input that sets record "Authorization" to value
|
||||
return (
|
||||
<TextInput
|
||||
{...props}
|
||||
{...restProps}
|
||||
label={"Ключ авторизации"}
|
||||
placeholder={"Введите ключ авторизации"}
|
||||
value={props.value["Authorization"] || ""}
|
||||
@@ -32,7 +36,7 @@ const MarketplaceAuthDataInput: FC<Props> = (props: Props) => {
|
||||
return (
|
||||
<>
|
||||
<NumberInput
|
||||
{...props}
|
||||
{...restProps}
|
||||
label={"Client-Id"}
|
||||
placeholder={"Введите Client-Id"}
|
||||
value={props.value["Client-Id"] || undefined}
|
||||
@@ -44,7 +48,7 @@ const MarketplaceAuthDataInput: FC<Props> = (props: Props) => {
|
||||
}
|
||||
/>
|
||||
<TextInput
|
||||
{...props}
|
||||
{...restProps}
|
||||
label={"Api-Key"}
|
||||
placeholder={"Введите Api-Key"}
|
||||
value={props.value["Api-Key"] || ""}
|
||||
@@ -59,6 +63,29 @@ const MarketplaceAuthDataInput: FC<Props> = (props: Props) => {
|
||||
);
|
||||
};
|
||||
const getYandexMarketInputs = () => {
|
||||
return (
|
||||
<>
|
||||
<TextInput
|
||||
{...restProps}
|
||||
label={"Api-Key"}
|
||||
placeholder={"Введите Api-Key"}
|
||||
value={props.value["Api-Key"] || ""}
|
||||
onChange={value => {
|
||||
props.onChange({
|
||||
...props.value,
|
||||
"Api-Key": value.target.value,
|
||||
});
|
||||
}}
|
||||
/>
|
||||
<YandexMarketCampaignSelect
|
||||
value={props.value["CampaignId"] || ""}
|
||||
onChange={value => props.onChange({
|
||||
...props.value,
|
||||
"CampaignId": value.id.toString(),
|
||||
})}
|
||||
authData={props.value} />
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
const getInputs = () => {
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import { ContextModalProps } from "@mantine/modals";
|
||||
import BaseFormModal, {
|
||||
CreateEditFormProps,
|
||||
} from "../../../ClientsPage/modals/BaseFormModal/BaseFormModal.tsx";
|
||||
import BaseFormModal, { CreateEditFormProps } from "../../../ClientsPage/modals/BaseFormModal/BaseFormModal.tsx";
|
||||
import { MarketplaceSchema } from "../../../../client";
|
||||
import { useForm } from "@mantine/form";
|
||||
import { Fieldset, Flex, rem, TextInput } from "@mantine/core";
|
||||
@@ -9,21 +7,24 @@ import BaseMarketplaceSelect from "../../../../components/Selects/BaseMarketplac
|
||||
import MarketplaceAuthDataInput from "./MarketplaceAuthDataInput.tsx";
|
||||
|
||||
type Props = CreateEditFormProps<MarketplaceSchema>;
|
||||
export type MarketplaceAuthData = Record<string, string>;
|
||||
|
||||
const MarketplaceFormModal = ({
|
||||
context,
|
||||
id,
|
||||
innerProps,
|
||||
}: ContextModalProps<Props>) => {
|
||||
context,
|
||||
id,
|
||||
innerProps,
|
||||
}: ContextModalProps<Props>) => {
|
||||
const isEditing = "element" in innerProps;
|
||||
const initialValue: Partial<MarketplaceSchema> = isEditing
|
||||
? innerProps.element
|
||||
: {
|
||||
authData: {
|
||||
"Authorization": "",
|
||||
"Client-Id": "",
|
||||
"Api-Key": "",
|
||||
},
|
||||
};
|
||||
authData: {
|
||||
"Authorization": "",
|
||||
"Client-Id": "",
|
||||
"Api-Key": "",
|
||||
"CampaignId": "",
|
||||
},
|
||||
};
|
||||
const form = useForm<Partial<MarketplaceSchema>>({
|
||||
initialValues: initialValue,
|
||||
validate: {
|
||||
|
||||
@@ -10,6 +10,7 @@ export default defineConfig({
|
||||
strictPort: true,
|
||||
hmr: {
|
||||
port: 5173,
|
||||
host: "127.0.0.1",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user