Skip to content

Commit

Permalink
feat(admin-ui): Add support for translatable Promotions
Browse files Browse the repository at this point in the history
Relates to #1990
  • Loading branch information
michaelbromley committed Feb 24, 2023
1 parent dada243 commit 00bd433
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 61 deletions.
36 changes: 29 additions & 7 deletions packages/admin-ui/src/lib/core/src/common/generated-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -804,9 +804,9 @@ export type CreatePromotionInput = {
customFields?: InputMaybe<Scalars['JSON']>;
enabled: Scalars['Boolean'];
endsAt?: InputMaybe<Scalars['DateTime']>;
name: Scalars['String'];
perCustomerUsageLimit?: InputMaybe<Scalars['Int']>;
startsAt?: InputMaybe<Scalars['DateTime']>;
translations: Array<PromotionTranslationInput>;
};

export type CreatePromotionResult = MissingConditionsError | Promotion;
Expand Down Expand Up @@ -4487,18 +4487,21 @@ export type Promotion = Node & {
couponCode?: Maybe<Scalars['String']>;
createdAt: Scalars['DateTime'];
customFields?: Maybe<Scalars['JSON']>;
description: Scalars['String'];
enabled: Scalars['Boolean'];
endsAt?: Maybe<Scalars['DateTime']>;
id: Scalars['ID'];
name: Scalars['String'];
perCustomerUsageLimit?: Maybe<Scalars['Int']>;
startsAt?: Maybe<Scalars['DateTime']>;
translations: Array<PromotionTranslation>;
updatedAt: Scalars['DateTime'];
};

export type PromotionFilterParameter = {
couponCode?: InputMaybe<StringOperators>;
createdAt?: InputMaybe<DateOperators>;
description?: InputMaybe<StringOperators>;
enabled?: InputMaybe<BooleanOperators>;
endsAt?: InputMaybe<DateOperators>;
id?: InputMaybe<IdOperators>;
Expand Down Expand Up @@ -4530,6 +4533,7 @@ export type PromotionListOptions = {
export type PromotionSortParameter = {
couponCode?: InputMaybe<SortOrder>;
createdAt?: InputMaybe<SortOrder>;
description?: InputMaybe<SortOrder>;
endsAt?: InputMaybe<SortOrder>;
id?: InputMaybe<SortOrder>;
name?: InputMaybe<SortOrder>;
Expand All @@ -4538,6 +4542,24 @@ export type PromotionSortParameter = {
updatedAt?: InputMaybe<SortOrder>;
};

export type PromotionTranslation = {
__typename?: 'PromotionTranslation';
createdAt: Scalars['DateTime'];
description: Scalars['String'];
id: Scalars['ID'];
languageCode: LanguageCode;
name: Scalars['String'];
updatedAt: Scalars['DateTime'];
};

export type PromotionTranslationInput = {
customFields?: InputMaybe<Scalars['JSON']>;
description?: InputMaybe<Scalars['String']>;
id?: InputMaybe<Scalars['ID']>;
languageCode: LanguageCode;
name?: InputMaybe<Scalars['String']>;
};

/** Returned if the specified quantity of an OrderLine is greater than the number of items in that line */
export type QuantityTooGreatError = ErrorResult & {
__typename?: 'QuantityTooGreatError';
Expand Down Expand Up @@ -5878,9 +5900,9 @@ export type UpdatePromotionInput = {
enabled?: InputMaybe<Scalars['Boolean']>;
endsAt?: InputMaybe<Scalars['DateTime']>;
id: Scalars['ID'];
name?: InputMaybe<Scalars['String']>;
perCustomerUsageLimit?: InputMaybe<Scalars['Int']>;
startsAt?: InputMaybe<Scalars['DateTime']>;
translations?: InputMaybe<Array<PromotionTranslationInput>>;
};

export type UpdatePromotionResult = MissingConditionsError | Promotion;
Expand Down Expand Up @@ -7088,21 +7110,21 @@ export type DeleteTagMutationVariables = Exact<{

export type DeleteTagMutation = { deleteTag: { __typename?: 'DeletionResponse', message?: string | null, result: DeletionResult } };

export type PromotionFragment = { __typename?: 'Promotion', id: string, createdAt: any, updatedAt: any, name: string, enabled: boolean, couponCode?: string | null, perCustomerUsageLimit?: number | null, startsAt?: any | null, endsAt?: any | null, conditions: Array<{ __typename?: 'ConfigurableOperation', code: string, args: Array<{ __typename?: 'ConfigArg', name: string, value: string }> }>, actions: Array<{ __typename?: 'ConfigurableOperation', code: string, args: Array<{ __typename?: 'ConfigArg', name: string, value: string }> }> };
export type PromotionFragment = { __typename?: 'Promotion', id: string, createdAt: any, updatedAt: any, name: string, description: string, enabled: boolean, couponCode?: string | null, perCustomerUsageLimit?: number | null, startsAt?: any | null, endsAt?: any | null, conditions: Array<{ __typename?: 'ConfigurableOperation', code: string, args: Array<{ __typename?: 'ConfigArg', name: string, value: string }> }>, actions: Array<{ __typename?: 'ConfigurableOperation', code: string, args: Array<{ __typename?: 'ConfigArg', name: string, value: string }> }>, translations: Array<{ __typename?: 'PromotionTranslation', id: string, languageCode: LanguageCode, name: string, description: string }> };

export type GetPromotionListQueryVariables = Exact<{
options?: InputMaybe<PromotionListOptions>;
}>;


export type GetPromotionListQuery = { promotions: { __typename?: 'PromotionList', totalItems: number, items: Array<{ __typename?: 'Promotion', id: string, createdAt: any, updatedAt: any, name: string, enabled: boolean, couponCode?: string | null, perCustomerUsageLimit?: number | null, startsAt?: any | null, endsAt?: any | null, conditions: Array<{ __typename?: 'ConfigurableOperation', code: string, args: Array<{ __typename?: 'ConfigArg', name: string, value: string }> }>, actions: Array<{ __typename?: 'ConfigurableOperation', code: string, args: Array<{ __typename?: 'ConfigArg', name: string, value: string }> }> }> } };
export type GetPromotionListQuery = { promotions: { __typename?: 'PromotionList', totalItems: number, items: Array<{ __typename?: 'Promotion', id: string, createdAt: any, updatedAt: any, name: string, description: string, enabled: boolean, couponCode?: string | null, perCustomerUsageLimit?: number | null, startsAt?: any | null, endsAt?: any | null, conditions: Array<{ __typename?: 'ConfigurableOperation', code: string, args: Array<{ __typename?: 'ConfigArg', name: string, value: string }> }>, actions: Array<{ __typename?: 'ConfigurableOperation', code: string, args: Array<{ __typename?: 'ConfigArg', name: string, value: string }> }>, translations: Array<{ __typename?: 'PromotionTranslation', id: string, languageCode: LanguageCode, name: string, description: string }> }> } };

export type GetPromotionQueryVariables = Exact<{
id: Scalars['ID'];
}>;


export type GetPromotionQuery = { promotion?: { __typename?: 'Promotion', id: string, createdAt: any, updatedAt: any, name: string, enabled: boolean, couponCode?: string | null, perCustomerUsageLimit?: number | null, startsAt?: any | null, endsAt?: any | null, conditions: Array<{ __typename?: 'ConfigurableOperation', code: string, args: Array<{ __typename?: 'ConfigArg', name: string, value: string }> }>, actions: Array<{ __typename?: 'ConfigurableOperation', code: string, args: Array<{ __typename?: 'ConfigArg', name: string, value: string }> }> } | null };
export type GetPromotionQuery = { promotion?: { __typename?: 'Promotion', id: string, createdAt: any, updatedAt: any, name: string, description: string, enabled: boolean, couponCode?: string | null, perCustomerUsageLimit?: number | null, startsAt?: any | null, endsAt?: any | null, conditions: Array<{ __typename?: 'ConfigurableOperation', code: string, args: Array<{ __typename?: 'ConfigArg', name: string, value: string }> }>, actions: Array<{ __typename?: 'ConfigurableOperation', code: string, args: Array<{ __typename?: 'ConfigArg', name: string, value: string }> }>, translations: Array<{ __typename?: 'PromotionTranslation', id: string, languageCode: LanguageCode, name: string, description: string }> } | null };

export type GetAdjustmentOperationsQueryVariables = Exact<{ [key: string]: never; }>;

Expand All @@ -7114,14 +7136,14 @@ export type CreatePromotionMutationVariables = Exact<{
}>;


export type CreatePromotionMutation = { createPromotion: { __typename?: 'MissingConditionsError', errorCode: ErrorCode, message: string } | { __typename?: 'Promotion', id: string, createdAt: any, updatedAt: any, name: string, enabled: boolean, couponCode?: string | null, perCustomerUsageLimit?: number | null, startsAt?: any | null, endsAt?: any | null, conditions: Array<{ __typename?: 'ConfigurableOperation', code: string, args: Array<{ __typename?: 'ConfigArg', name: string, value: string }> }>, actions: Array<{ __typename?: 'ConfigurableOperation', code: string, args: Array<{ __typename?: 'ConfigArg', name: string, value: string }> }> } };
export type CreatePromotionMutation = { createPromotion: { __typename?: 'MissingConditionsError', errorCode: ErrorCode, message: string } | { __typename?: 'Promotion', id: string, createdAt: any, updatedAt: any, name: string, description: string, enabled: boolean, couponCode?: string | null, perCustomerUsageLimit?: number | null, startsAt?: any | null, endsAt?: any | null, conditions: Array<{ __typename?: 'ConfigurableOperation', code: string, args: Array<{ __typename?: 'ConfigArg', name: string, value: string }> }>, actions: Array<{ __typename?: 'ConfigurableOperation', code: string, args: Array<{ __typename?: 'ConfigArg', name: string, value: string }> }>, translations: Array<{ __typename?: 'PromotionTranslation', id: string, languageCode: LanguageCode, name: string, description: string }> } };

export type UpdatePromotionMutationVariables = Exact<{
input: UpdatePromotionInput;
}>;


export type UpdatePromotionMutation = { updatePromotion: { __typename?: 'MissingConditionsError' } | { __typename?: 'Promotion', id: string, createdAt: any, updatedAt: any, name: string, enabled: boolean, couponCode?: string | null, perCustomerUsageLimit?: number | null, startsAt?: any | null, endsAt?: any | null, conditions: Array<{ __typename?: 'ConfigurableOperation', code: string, args: Array<{ __typename?: 'ConfigArg', name: string, value: string }> }>, actions: Array<{ __typename?: 'ConfigurableOperation', code: string, args: Array<{ __typename?: 'ConfigArg', name: string, value: string }> }> } };
export type UpdatePromotionMutation = { updatePromotion: { __typename?: 'MissingConditionsError' } | { __typename?: 'Promotion', id: string, createdAt: any, updatedAt: any, name: string, description: string, enabled: boolean, couponCode?: string | null, perCustomerUsageLimit?: number | null, startsAt?: any | null, endsAt?: any | null, conditions: Array<{ __typename?: 'ConfigurableOperation', code: string, args: Array<{ __typename?: 'ConfigArg', name: string, value: string }> }>, actions: Array<{ __typename?: 'ConfigurableOperation', code: string, args: Array<{ __typename?: 'ConfigArg', name: string, value: string }> }>, translations: Array<{ __typename?: 'PromotionTranslation', id: string, languageCode: LanguageCode, name: string, description: string }> } };

export type DeletePromotionMutationVariables = Exact<{
id: Scalars['ID'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const PROMOTION_FRAGMENT = gql`
createdAt
updatedAt
name
description
enabled
couponCode
perCustomerUsageLimit
Expand All @@ -23,6 +24,12 @@ export const PROMOTION_FRAGMENT = gql`
actions {
...ConfigurableOperation
}
translations {
id
languageCode
name
description
}
}
${CONFIGURABLE_OPERATION_FRAGMENT}
`;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { pick } from '@vendure/common/lib/pick';

import * as Codegen from '../../common/generated-types';
import {
CREATE_PROMOTION,
Expand Down Expand Up @@ -44,7 +46,17 @@ export class PromotionDataService {
Codegen.CreatePromotionMutation,
Codegen.CreatePromotionMutationVariables
>(CREATE_PROMOTION, {
input,
input: pick(input, [
'conditions',
'actions',
'couponCode',
'startsAt',
'endsAt',
'perCustomerUsageLimit',
'enabled',
'translations',
'customFields',
]),
});
}

Expand All @@ -53,7 +65,18 @@ export class PromotionDataService {
Codegen.UpdatePromotionMutation,
Codegen.UpdatePromotionMutationVariables
>(UPDATE_PROMOTION, {
input,
input: pick(input, [
'id',
'conditions',
'actions',
'couponCode',
'startsAt',
'endsAt',
'perCustomerUsageLimit',
'enabled',
'translations',
'customFields',
]),
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
<input type="checkbox" clrToggle name="enabled" [formControl]="detailForm.get(['enabled'])" />
<label>{{ 'common.enabled' | translate }}</label>
</clr-toggle-wrapper>
<vdr-language-selector
[disabled]="isNew$ | async"
[availableLanguageCodes]="availableLanguages$ | async"
[currentLanguageCode]="languageCode$ | async"
(languageCodeChange)="setLanguage($event)"
></vdr-language-selector>
</div>
</vdr-ab-left>

Expand Down Expand Up @@ -41,6 +47,11 @@
formControlName="name"
/>
</vdr-form-field>
<vdr-rich-text-editor
formControlName="description"
[readonly]="!('UpdatePromotion' | hasPermission)"
[label]="'common.description' | translate"
></vdr-rich-text-editor>
<vdr-form-field [label]="'marketing.starts-at' | translate" for="startsAt">
<vdr-datetime-picker formControlName="startsAt"></vdr-datetime-picker>
</vdr-form-field>
Expand Down
Loading

0 comments on commit 00bd433

Please sign in to comment.