Skip to content

Commit

Permalink
feat(admin-ui): Can delete TaxRate via list view
Browse files Browse the repository at this point in the history
Relates to #262
  • Loading branch information
michaelbromley committed Feb 12, 2020
1 parent 8c2db90 commit ee02aa2
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 2 deletions.
27 changes: 27 additions & 0 deletions packages/admin-ui/src/app/common/generated-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1809,10 +1809,14 @@ export type Mutation = {
createTaxCategory: TaxCategory,
/** Update an existing TaxCategory */
updateTaxCategory: TaxCategory,
/** Deletes a TaxCategory */
deleteTaxCategory: DeletionResponse,
/** Create a new TaxRate */
createTaxRate: TaxRate,
/** Update an existing TaxRate */
updateTaxRate: TaxRate,
/** Delete a TaxRate */
deleteTaxRate: DeletionResponse,
/** Create a new Zone */
createZone: Zone,
/** Update an existing Zone */
Expand Down Expand Up @@ -2169,6 +2173,11 @@ export type MutationUpdateTaxCategoryArgs = {
};


export type MutationDeleteTaxCategoryArgs = {
id: Scalars['ID']
};


export type MutationCreateTaxRateArgs = {
input: CreateTaxRateInput
};
Expand All @@ -2179,6 +2188,11 @@ export type MutationUpdateTaxRateArgs = {
};


export type MutationDeleteTaxRateArgs = {
id: Scalars['ID']
};


export type MutationCreateZoneArgs = {
input: CreateZoneInput
};
Expand Down Expand Up @@ -4332,6 +4346,13 @@ export type UpdateTaxRateMutationVariables = {

export type UpdateTaxRateMutation = ({ __typename?: 'Mutation' } & { updateTaxRate: ({ __typename?: 'TaxRate' } & TaxRateFragment) });

export type DeleteTaxRateMutationVariables = {
id: Scalars['ID']
};


export type DeleteTaxRateMutation = ({ __typename?: 'Mutation' } & { deleteTaxRate: ({ __typename?: 'DeletionResponse' } & Pick<DeletionResponse, 'result' | 'message'>) });

export type ChannelFragment = ({ __typename?: 'Channel' } & Pick<Channel, 'id' | 'createdAt' | 'updatedAt' | 'code' | 'token' | 'pricesIncludeTax' | 'currencyCode' | 'defaultLanguageCode'> & { defaultShippingZone: Maybe<({ __typename?: 'Zone' } & Pick<Zone, 'id' | 'name'>)>, defaultTaxZone: Maybe<({ __typename?: 'Zone' } & Pick<Zone, 'id' | 'name'>)> });

export type GetChannelsQueryVariables = {};
Expand Down Expand Up @@ -5326,6 +5347,12 @@ export namespace UpdateTaxRate {
export type UpdateTaxRate = TaxRateFragment;
}

export namespace DeleteTaxRate {
export type Variables = DeleteTaxRateMutationVariables;
export type Mutation = DeleteTaxRateMutation;
export type DeleteTaxRate = DeleteTaxRateMutation['deleteTaxRate'];
}

export namespace Channel {
export type Fragment = ChannelFragment;
export type DefaultShippingZone = (NonNullable<ChannelFragment['defaultShippingZone']>);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,15 @@ export const UPDATE_TAX_RATE = gql`
${TAX_RATE_FRAGMENT}
`;

export const DELETE_TAX_RATE = gql`
mutation DeleteTaxRate($id: ID!) {
deleteTaxRate(id: $id) {
result
message
}
}
`;

export const CHANNEL_FRAGMENT = gql`
fragment Channel on Channel {
id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
CreateZoneInput,
DeleteChannel,
DeleteCountry,
DeleteTaxRate,
GetActiveChannel,
GetAllJobs,
GetAvailableCountries,
Expand Down Expand Up @@ -59,6 +60,7 @@ import {
CREATE_ZONE,
DELETE_CHANNEL,
DELETE_COUNTRY,
DELETE_TAX_RATE,
GET_ACTIVE_CHANNEL,
GET_ALL_JOBS,
GET_AVAILABLE_COUNTRIES,
Expand Down Expand Up @@ -228,6 +230,12 @@ export class SettingsDataService {
});
}

deleteTaxRate(id: string) {
return this.baseDataService.mutate<DeleteTaxRate.Mutation, DeleteTaxRate.Variables>(DELETE_TAX_RATE, {
id,
});
}

getChannels() {
return this.baseDataService.query<GetChannels.Query>(GET_CHANNELS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<vdr-dt-column>{{ 'settings.zone' | translate }}</vdr-dt-column>
<vdr-dt-column>{{ 'settings.tax-rate' | translate }}</vdr-dt-column>
<vdr-dt-column></vdr-dt-column>
<vdr-dt-column></vdr-dt-column>
<ng-template let-taxRate="item">
<td class="left align-middle">{{ taxRate.name }}</td>
<td class="left align-middle">{{ taxRate.category.name }}</td>
Expand All @@ -33,5 +34,25 @@
[linkTo]="['./', taxRate.id]"
></vdr-table-row-action>
</td>
<td class="right align-middle">
<vdr-dropdown>
<button type="button" class="btn btn-link btn-sm" vdrDropdownTrigger>
{{ 'common.actions' | translate }}
<clr-icon shape="caret down"></clr-icon>
</button>
<vdr-dropdown-menu vdrPosition="bottom-right">
<button
type="button"
class="delete-button"
(click)="deleteTaxRate(taxRate)"
[disabled]="!('DeleteSettings' | hasPermission)"
vdrDropdownItem
>
<clr-icon shape="trash" class="is-danger"></clr-icon>
{{ 'common.delete' | translate }}
</button>
</vdr-dropdown-menu>
</vdr-dropdown>
</td>
</ng-template>
</vdr-data-table>
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { EMPTY } from 'rxjs';
import { map, switchMap } from 'rxjs/operators';

import { BaseListComponent } from '../../../common/base-list.component';
import { GetTaxRateList } from '../../../common/generated-types';
import { DeletionResult, GetTaxRateList } from '../../../common/generated-types';
import { _ } from '../../../core/providers/i18n/mark-for-extraction';
import { NotificationService } from '../../../core/providers/notification/notification.service';
import { DataService } from '../../../data/providers/data.service';
import { ModalService } from '../../../shared/providers/modal/modal.service';

@Component({
selector: 'vdr-tax-rate-list',
Expand All @@ -12,11 +17,52 @@ import { DataService } from '../../../data/providers/data.service';
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class TaxRateListComponent extends BaseListComponent<GetTaxRateList.Query, GetTaxRateList.Items> {
constructor(private dataService: DataService, router: Router, route: ActivatedRoute) {
constructor(
private modalService: ModalService,
private notificationService: NotificationService,
private dataService: DataService,
router: Router,
route: ActivatedRoute,
) {
super(router, route);
super.setQueryFn(
(...args: any[]) => this.dataService.settings.getTaxRates(...args),
data => data.taxRates,
);
}

deleteTaxRate(taxRate: GetTaxRateList.Items) {
return this.modalService
.dialog({
title: _('settings.confirm-delete-tax-rate'),
body: taxRate.name,
buttons: [
{ type: 'secondary', label: _('common.cancel') },
{ type: 'danger', label: _('common.delete'), returnValue: true },
],
})
.pipe(
switchMap(res => (res ? this.dataService.settings.deleteTaxRate(taxRate.id) : EMPTY)),
map(res => res.deleteTaxRate),
)
.subscribe(
res => {
if (res.result === DeletionResult.DELETED) {
this.notificationService.success(_('common.notify-delete-success'), {
entity: 'TaxRate',
});
this.refresh();
} else {
this.notificationService.error(res.message || _('common.notify-delete-error'), {
entity: 'TaxRate',
});
}
},
err => {
this.notificationService.error(_('common.notify-delete-error'), {
entity: 'TaxRate',
});
},
);
}
}
1 change: 1 addition & 0 deletions packages/admin-ui/src/i18n-messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@
"channel": "Channel",
"channel-token": "Channel token",
"confirm-delete-role": "Delete role?",
"confirm-delete-tax-rate": "Delete tax rate?",
"create": "Create",
"create-new-channel": "Create new channel",
"create-new-country": "Create new country",
Expand Down

0 comments on commit ee02aa2

Please sign in to comment.