Skip to content

Commit

Permalink
feat(admin-ui): Implement default TaxCategory support
Browse files Browse the repository at this point in the history
Relates to #566
  • Loading branch information
michaelbromley committed Feb 1, 2021
1 parent 7eb21d1 commit 90ed7c4
Show file tree
Hide file tree
Showing 16 changed files with 54 additions and 22 deletions.
26 changes: 13 additions & 13 deletions packages/admin-ui/i18n-coverage.json
Original file line number Diff line number Diff line change
@@ -1,49 +1,49 @@
{
"generatedOn": "2021-02-01T13:23:30.145Z",
"lastCommit": "56c39f8ada2711dd731de4543e48358d24212b3f",
"generatedOn": "2021-02-01T20:16:12.347Z",
"lastCommit": "7eb21d16d0c17f87e9cc267a024b937c2e4deefa",
"translationStatus": {
"cs": {
"tokenCount": 767,
"tokenCount": 768,
"translatedCount": 753,
"percentage": 98
},
"de": {
"tokenCount": 767,
"tokenCount": 768,
"translatedCount": 594,
"percentage": 77
},
"en": {
"tokenCount": 767,
"translatedCount": 764,
"tokenCount": 768,
"translatedCount": 767,
"percentage": 100
},
"es": {
"tokenCount": 767,
"tokenCount": 768,
"translatedCount": 456,
"percentage": 59
},
"fr": {
"tokenCount": 767,
"tokenCount": 768,
"translatedCount": 690,
"percentage": 90
},
"pl": {
"tokenCount": 767,
"tokenCount": 768,
"translatedCount": 549,
"percentage": 72
"percentage": 71
},
"pt_BR": {
"tokenCount": 767,
"tokenCount": 768,
"translatedCount": 749,
"percentage": 98
},
"zh_Hans": {
"tokenCount": 767,
"tokenCount": 768,
"translatedCount": 531,
"percentage": 69
},
"zh_Hant": {
"tokenCount": 767,
"tokenCount": 768,
"translatedCount": 531,
"percentage": 69
}
Expand Down
5 changes: 4 additions & 1 deletion packages/admin-ui/src/lib/core/src/common/generated-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2418,11 +2418,13 @@ export type UpdateTagInput = {

export type CreateTaxCategoryInput = {
name: Scalars['String'];
isDefault?: Maybe<Scalars['Boolean']>;
};

export type UpdateTaxCategoryInput = {
id: Scalars['ID'];
name?: Maybe<Scalars['String']>;
isDefault?: Maybe<Scalars['Boolean']>;
};

export type CreateTaxRateInput = {
Expand Down Expand Up @@ -4224,6 +4226,7 @@ export type TaxCategory = Node & {
createdAt: Scalars['DateTime'];
updatedAt: Scalars['DateTime'];
name: Scalars['String'];
isDefault: Scalars['Boolean'];
};

export type TaxRate = Node & {
Expand Down Expand Up @@ -6925,7 +6928,7 @@ export type RemoveMembersFromZoneMutation = { removeMembersFromZone: (

export type TaxCategoryFragment = (
{ __typename?: 'TaxCategory' }
& Pick<TaxCategory, 'id' | 'createdAt' | 'updatedAt' | 'name'>
& Pick<TaxCategory, 'id' | 'createdAt' | 'updatedAt' | 'name' | 'isDefault'>
);

export type GetTaxCategoriesQueryVariables = Exact<{ [key: string]: never; }>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ export const TAX_CATEGORY_FRAGMENT = gql`
createdAt
updatedAt
name
isDefault
}
`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,15 @@
[readonly]="!('UpdateSettings' | hasPermission)"
/>
</vdr-form-field>
<vdr-form-field [label]="'common.default-tax-category' | translate" for="isDefault">
<clr-toggle-wrapper>
<input
type="checkbox"
clrToggle
id="isDefault"
[vdrDisabled]="!('UpdateSettings' | hasPermission)"
formControlName="isDefault"
/>
</clr-toggle-wrapper>
</vdr-form-field>
</form>
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import { mergeMap, take } from 'rxjs/operators';
styleUrls: ['./tax-category-detail.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class TaxCategoryDetailComponent extends BaseDetailComponent<TaxCategory.Fragment>
export class TaxCategoryDetailComponent
extends BaseDetailComponent<TaxCategory.Fragment>
implements OnInit, OnDestroy {
taxCategory$: Observable<TaxCategory.Fragment>;
detailForm: FormGroup;
Expand All @@ -42,7 +43,7 @@ export class TaxCategoryDetailComponent extends BaseDetailComponent<TaxCategory.
super(route, router, serverConfigService, dataService);
this.detailForm = this.formBuilder.group({
name: ['', Validators.required],
taxRate: [0, Validators.required],
isDefault: false,
});
}

Expand All @@ -64,17 +65,17 @@ export class TaxCategoryDetailComponent extends BaseDetailComponent<TaxCategory.
return;
}
const formValue = this.detailForm.value;
const input = { name: formValue.name } as CreateTaxCategoryInput;
const input = { name: formValue.name, isDefault: formValue.isDefault } as CreateTaxCategoryInput;
this.dataService.settings.createTaxCategory(input).subscribe(
(data) => {
data => {
this.notificationService.success(_('common.notify-create-success'), {
entity: 'TaxCategory',
});
this.detailForm.markAsPristine();
this.changeDetector.markForCheck();
this.router.navigate(['../', data.createTaxCategory.id], { relativeTo: this.route });
},
(err) => {
err => {
this.notificationService.error(_('common.notify-create-error'), {
entity: 'TaxCategory',
});
Expand All @@ -90,23 +91,24 @@ export class TaxCategoryDetailComponent extends BaseDetailComponent<TaxCategory.
this.taxCategory$
.pipe(
take(1),
mergeMap((taxCategory) => {
mergeMap(taxCategory => {
const input = {
id: taxCategory.id,
name: formValue.name,
isDefault: formValue.isDefault,
} as UpdateTaxCategoryInput;
return this.dataService.settings.updateTaxCategory(input);
}),
)
.subscribe(
(data) => {
data => {
this.notificationService.success(_('common.notify-update-success'), {
entity: 'TaxCategory',
});
this.detailForm.markAsPristine();
this.changeDetector.markForCheck();
},
(err) => {
err => {
this.notificationService.error(_('common.notify-update-error'), {
entity: 'TaxCategory',
});
Expand All @@ -120,6 +122,7 @@ export class TaxCategoryDetailComponent extends BaseDetailComponent<TaxCategory.
protected setFormValues(entity: TaxCategory.Fragment, languageCode: LanguageCode): void {
this.detailForm.patchValue({
name: entity.name,
isDefault: entity.isDefault,
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@
<vdr-dt-column>{{ 'common.name' | translate }}</vdr-dt-column>
<vdr-dt-column></vdr-dt-column>
<vdr-dt-column></vdr-dt-column>
<vdr-dt-column></vdr-dt-column>
<ng-template let-taxCategory="item">
<td class="left align-middle">{{ taxCategory.name }}</td>
<td class="left align-middle">
<vdr-chip *ngIf="taxCategory.isDefault">{{ 'common.default-tax-category' | translate }}</vdr-chip>
</td>
<td class="right align-middle">
<vdr-table-row-action
iconShape="edit"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class TaxCategoryResolver extends BaseEntityResolver<TaxCategory.Fragment
createdAt: '',
updatedAt: '',
name: '',
isDefault: false,
},
id => dataService.settings.getTaxCategory(id).mapStream(data => data.taxCategory),
);
Expand Down
1 change: 1 addition & 0 deletions packages/admin-ui/src/lib/static/i18n-messages/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@
"custom-fields": "Extra pole",
"default-channel": "Výchozí kanál",
"default-language": "Výchozí jazyk",
"default-tax-category": "",
"delete": "Smazat",
"description": "Popis",
"details": "Detaily",
Expand Down
1 change: 1 addition & 0 deletions packages/admin-ui/src/lib/static/i18n-messages/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@
"custom-fields": "Benutzerdefinierte Felder",
"default-channel": "Standardkanal",
"default-language": "Standardsprache",
"default-tax-category": "",
"delete": "Löschen",
"description": "Beschreibung",
"details": "",
Expand Down
1 change: 1 addition & 0 deletions packages/admin-ui/src/lib/static/i18n-messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@
"custom-fields": "Custom fields",
"default-channel": "Default channel",
"default-language": "Default language",
"default-tax-category": "Default tax category",
"delete": "Delete",
"description": "Description",
"details": "Details",
Expand Down
1 change: 1 addition & 0 deletions packages/admin-ui/src/lib/static/i18n-messages/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@
"custom-fields": "Campos personalizados",
"default-channel": "Canal de ventas por defecto",
"default-language": "Idioma por defecto",
"default-tax-category": "",
"delete": "Eliminar",
"description": "Descripción",
"details": "Detalles",
Expand Down
1 change: 1 addition & 0 deletions packages/admin-ui/src/lib/static/i18n-messages/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@
"custom-fields": "Champs personnalisés",
"default-channel": "Canal par défaut",
"default-language": "Langue par défaut",
"default-tax-category": "",
"delete": "Supprimer",
"description": "Description",
"details": "Détails",
Expand Down
1 change: 1 addition & 0 deletions packages/admin-ui/src/lib/static/i18n-messages/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@
"custom-fields": "Dodatkowe pola",
"default-channel": "Domyślny kanał",
"default-language": "Domyślny jezyk",
"default-tax-category": "",
"delete": "Usuń",
"description": "Opis",
"details": "",
Expand Down
1 change: 1 addition & 0 deletions packages/admin-ui/src/lib/static/i18n-messages/pt_BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@
"custom-fields": "Campos customizados",
"default-channel": "Canal padrão",
"default-language": "Idioma padrão",
"default-tax-category": "",
"delete": "Excluir",
"description": "Descrição",
"details": "Detalhes",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@
"custom-fields": "客户化字段",
"default-channel": "默认销售渠道",
"default-language": "",
"default-tax-category": "",
"delete": "删除",
"description": "描述",
"details": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@
"custom-fields": "客戶自訂欄位",
"default-channel": "默認渠道",
"default-language": "",
"default-tax-category": "",
"delete": "移除",
"description": "描述",
"details": "",
Expand Down

0 comments on commit 90ed7c4

Please sign in to comment.