diff --git a/src/client/index.ts b/src/client/index.ts index f10d6ba..7566030 100644 --- a/src/client/index.ts +++ b/src/client/index.ts @@ -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'; diff --git a/src/client/models/GetYandexMarketCampaignsRequest.ts b/src/client/models/GetYandexMarketCampaignsRequest.ts new file mode 100644 index 0000000..f5a3b1c --- /dev/null +++ b/src/client/models/GetYandexMarketCampaignsRequest.ts @@ -0,0 +1,8 @@ +/* generated using openapi-typescript-codegen -- do not edit */ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export type GetYandexMarketCampaignsRequest = { + apiKey: string; +}; + diff --git a/src/client/models/GetYandexMarketCampaignsResponse.ts b/src/client/models/GetYandexMarketCampaignsResponse.ts new file mode 100644 index 0000000..5efd813 --- /dev/null +++ b/src/client/models/GetYandexMarketCampaignsResponse.ts @@ -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; +}; + diff --git a/src/client/models/YandexMarketCampaignSchema.ts b/src/client/models/YandexMarketCampaignSchema.ts new file mode 100644 index 0000000..384d5b8 --- /dev/null +++ b/src/client/models/YandexMarketCampaignSchema.ts @@ -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; +}; + diff --git a/src/client/services/MarketplaceService.ts b/src/client/services/MarketplaceService.ts index 35e7fd4..a1b58ca 100644 --- a/src/client/services/MarketplaceService.ts +++ b/src/client/services/MarketplaceService.ts @@ -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 { + return __request(OpenAPI, { + method: 'POST', + url: '/marketplace/yandex-market/get-campaigns', + body: requestBody, + mediaType: 'application/json', + errors: { + 422: `Validation Error`, + }, + }); + } } diff --git a/src/components/Selects/YandexMarketCampaignSelect/YandexMarketCampaignSelect.tsx b/src/components/Selects/YandexMarketCampaignSelect/YandexMarketCampaignSelect.tsx new file mode 100644 index 0000000..734c10d --- /dev/null +++ b/src/components/Selects/YandexMarketCampaignSelect/YandexMarketCampaignSelect.tsx @@ -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 & 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 ( +