Skip to content

Commit

Permalink
Feat: retry transfer in activity log
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterSmallenbroek committed Feb 5, 2025
1 parent 96d1da5 commit 434205e
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 55 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<app-confirmation-dialog
#retryTransfersConfirmationDialog
header="Retry failed transfers"
header="Retry failed transfer(s)"
i18n-header="@@retry-failed-transfers"
headerIcon="pi pi-refresh"
proceedLabel="Retry transfers"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import {
import { injectMutation } from '@tanstack/angular-query-experimental';

import { ConfirmationDialogComponent } from '~/components/confirmation-dialog/confirmation-dialog.component';
import { QueryTableComponent } from '~/components/query-table/query-table.component';
import { MetricApiService } from '~/domains/metric/metric.api.service';
import { PaymentMetricDetails } from '~/domains/metric/metric.model';
import { PaymentApiService } from '~/domains/payment/payment.api.service';
import { ToastService } from '~/services/toast.service';

Expand All @@ -30,7 +28,6 @@ export class RetryTransfersDialogComponent {

private metricApiService = inject(MetricApiService);
private paymentApiService = inject(PaymentApiService);
private toastService = inject(ToastService);

referenceIdsForRetryTransfers = signal<string[]>([]);

Expand All @@ -55,37 +52,7 @@ export class RetryTransfersDialogComponent {
},
}));

public retryFailedTransfers({
table,
triggeredFromContextMenu,
contextMenuItem,
}: {
table: QueryTableComponent<PaymentMetricDetails, never>;
triggeredFromContextMenu: boolean;
contextMenuItem?: PaymentMetricDetails;
}) {
const actionData = table.getActionData({
triggeredFromContextMenu,
contextMenuItem,
fieldForFilter: 'referenceId',
noSelectionToastMessage: $localize`:@@no-registrations-selected:Select one or more registrations and try again.`,
});

if (!actionData) {
return;
}

const selection = actionData.selection;

if (!Array.isArray(selection) || selection.length === 0) {
this.toastService.showGenericError(); // Should never happen
return;
}

const referenceIds = selection.map(
(transaction) => transaction.referenceId,
);

public retryFailedTransfers({ referenceIds }: { referenceIds: string[] }) {
this.referenceIdsForRetryTransfers.set(referenceIds);
this.retryTransfersConfirmationDialog().askForConfirmation();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
>
@if (canRetryTransfers()) {
<p-button
label="Retry failed transfers"
label="Retry failed transfer(s)"
i18n-label="@@retry-failed-transfers"
rounded
outlined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,11 +349,30 @@ export class ProjectPaymentPageComponent {
});
return;
}

this.retryTransfersDialog().retryFailedTransfers({
table: this.table(),
const actionData = this.table().getActionData({
triggeredFromContextMenu,
contextMenuItem: this.contextMenuSelection(),
fieldForFilter: 'referenceId',
noSelectionToastMessage: $localize`:@@no-registrations-selected:Select one or more registrations and try again.`,
});

if (!actionData) {
return;
}

const selection = actionData.selection;

if (!Array.isArray(selection) || selection.length === 0) {
this.toastService.showGenericError(); // Should never happen
return;
}

const referenceIds = selection.map(
(transaction) => transaction.referenceId,
);

this.retryTransfersDialog().retryFailedTransfers({
referenceIds,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ import {
inject,
input,
LOCALE_ID,
viewChild,
} from '@angular/core';

import { injectQuery } from '@tanstack/angular-query-experimental';
import { ButtonModule } from 'primeng/button';
import { ChipModule } from 'primeng/chip';

import { ActivityTypeEnum } from '@121-service/src/activities/enum/activity-type.enum';
import { FinancialServiceProviders } from '@121-service/src/financial-service-providers/enum/financial-service-provider-name.enum';
import { TransactionStatusEnum } from '@121-service/src/payments/transactions/enums/transaction-status.enum';
import { GenericRegistrationAttributes } from '@121-service/src/registration/enum/registration-attribute.enum';
import { PermissionEnum } from '@121-service/src/user/enum/permission.enum';

import { ColoredChipComponent } from '~/components/colored-chip/colored-chip.component';
import {
Expand All @@ -28,8 +32,10 @@ import {
REGISTRATION_STATUS_LABELS,
} from '~/domains/registration/registration.helper';
import { Activity } from '~/domains/registration/registration.model';
import { RetryTransfersDialogComponent } from '~/pages/project-payment/components/retry-transfers-dialog/retry-transfers-dialog.component';
import { ActivityLogVoucherDialogComponent } from '~/pages/project-registration-activity-log/components/activity-log-voucher-dialog/activity-log-voucher-dialog.component';
import { ActivityLogTableCellContext } from '~/pages/project-registration-activity-log/project-registration-activity-log.page';
import { AuthService } from '~/services/auth.service';
import { RegistrationAttributeService } from '~/services/registration-attribute.service';
import { Locale } from '~/utils/locale';

Expand All @@ -39,6 +45,8 @@ import { Locale } from '~/utils/locale';
ChipModule,
ColoredChipComponent,
ActivityLogVoucherDialogComponent,
ButtonModule,
RetryTransfersDialogComponent,
],
template: `
<div class="flex w-full content-between items-center">
Expand All @@ -52,6 +60,16 @@ import { Locale } from '~/utils/locale';
[label]="chipData()!.chipLabel"
[variant]="chipData()!.chipVariant"
/>
@if (canRetryTransfer()) {
<p-button
class="ms-1"
label="Retry transfer"
i18n-label="@@retry-transfer"
rounded
size="small"
(click)="retryTransfer()"
/>
}
</div>
}
Expand All @@ -64,6 +82,15 @@ import { Locale } from '~/utils/locale';
[voucherReferenceId]="dialogData.voucherReferenceId"
/>
}
@let payment = paymentId();
@if (payment && canRetryTransfer()) {
<app-retry-transfers-dialog
#retryTransfersDialog
[projectId]="context().projectId()"
[paymentId]="payment"
/>
}
</div>
`,
styles: ``,
Expand All @@ -76,7 +103,11 @@ export class TableCellOverviewComponent
context = input.required<ActivityLogTableCellContext>();
locale = inject<Locale>(LOCALE_ID);

readonly retryTransfersDialog =
viewChild.required<RetryTransfersDialogComponent>('retryTransfersDialog');

readonly registrationAttributeService = inject(RegistrationAttributeService);
readonly authService = inject(AuthService);

readonly registrationAttributes = injectQuery(
this.registrationAttributeService.getRegistrationAttributes(this.context),
Expand All @@ -96,6 +127,14 @@ export class TableCellOverviewComponent
return undefined;
});

paymentId = computed(() => {
const item = this.value();
if (item.type === ActivityTypeEnum.Transaction) {
return item.attributes.payment.toString();
}
return undefined;
});

overview = computed(() => {
const item = this.value();
switch (item.type) {
Expand All @@ -122,6 +161,27 @@ export class TableCellOverviewComponent
}
});

canRetryTransfer = computed(() => {
const item = this.value();
if (
!this.authService.hasAllPermissions({
projectId: this.context().projectId(),
requiredPermissions: [
PermissionEnum.PaymentREAD,
PermissionEnum.PaymentCREATE,
PermissionEnum.PaymentTransactionREAD,
],
})
) {
return false;
}

if (item.type !== ActivityTypeEnum.Transaction) {
return false;
}
return item.attributes.status === TransactionStatusEnum.error;
});

voucherDialogData = computed(() => {
const item = this.value();
const referenceId = this.context().referenceId;
Expand All @@ -145,4 +205,22 @@ export class TableCellOverviewComponent
voucherReferenceId: referenceId,
};
});

retryTransfer() {
// TODO: Not sure if this still needs to be checked
// if (this.paymentStatus.data()?.inProgress) {
// this.toastService.showToast({
// severity: 'warn',
// detail: $localize`A payment is currently in progress. Please wait until it has finished.`,
// });
// return;
// }
const referenceId = this.context().referenceId;
if (referenceId) {
const referenceIds = [referenceId];
this.retryTransfersDialog().retryFailedTransfers({
referenceIds,
});
}
}
}
34 changes: 19 additions & 15 deletions interfaces/Portalicious/src/locale/messages.nl.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@
</trans-unit>
<trans-unit id="2982203751444563776" datatype="html">
<source>There are no registrations in this project yet.<x ctype="lb" equiv-text="&lt;br /&gt;" id="LINE_BREAK"/> For information about importing registrations to your project check out the <x ctype="x-a" equiv-text="&lt;a href=&quot;https://new.manual.121.global/&quot; target=&quot;_blank&quot; title=&quot;Opens in a new window&quot; i18n-title=&quot;@@generic-opens-in-new-window&quot; &gt;" id="START_LINK"/> 121 Manual <x ctype="x-span" equiv-text="&lt;span class=&quot;p-button-icon p-button-icon-right pi pi-external-link ml-1 text-sm&quot; &gt;" id="START_TAG_SPAN"/><x ctype="x-span" equiv-text="&lt;/span&gt;" id="CLOSE_TAG_SPAN"/><x ctype="x-a" equiv-text="&lt;/a &gt;" id="CLOSE_LINK"/>.</source>
<target>Er zijn nog geen registraties in dit project.<x ctype="lb" equiv-text="&lt;br /&gt;" id="LINE_BREAK"/> Voor informatie over het importeren van registraties in uw project kunt u terecht op de <x ctype="x-a" equiv-text="&lt;a href=&quot;https://new.manual.121.global/&quot; target=&quot;_blank&quot; title=&quot;Opens in a new window&quot; i18n-title=&quot;@@generic-opens-in-new-window&quot; &gt;" id="START_LINK"/> 121 Handleiding <x ctype="x-span" equiv-text="&lt;span class=&quot;p-button-icon p-button-icon-right pi pi-external-link ml-1 text-sm&quot; &gt;" id="START_TAG_SPAN"/><x ctype="x-span" equiv-text="&lt;/span&gt;" id="CLOSE_TAG_SPAN"/><x ctype="x-a" equiv-text="&lt;/a &gt;" id="CLOSE_LINK"/>.</target>
<target state="new">Er zijn nog geen registraties in dit project.<x ctype="lb" equiv-text="&lt;br /&gt;" id="LINE_BREAK"/> Voor informatie over het importeren van registraties in uw project kunt u terecht op de <x ctype="x-a" equiv-text="&lt;a href=&quot;https://manual.121.global/&quot; target=&quot;_blank&quot; title=&quot;Opens in a new window&quot; i18n-title=&quot;@@generic-opens-in-new-window&quot; &gt;" id="START_LINK"/> 121 Handleiding <x ctype="x-span" equiv-text="&lt;span class=&quot;p-button-icon p-button-icon-right pi pi-external-link ml-1 text-sm&quot; &gt;" id="START_TAG_SPAN"/><x ctype="x-span" equiv-text="&lt;/span&gt;" id="CLOSE_TAG_SPAN"/><x ctype="x-a" equiv-text="&lt;/a &gt;" id="CLOSE_LINK"/>.</target>
</trans-unit>
<trans-unit id="3003940161121195414" datatype="html">
<source>Update information</source>
Expand Down Expand Up @@ -783,7 +783,7 @@
</trans-unit>
<trans-unit id="5172848657173998509" datatype="html">
<source>You are about to add a note to <x equiv-text="{{ registration.data()?.name }}" id="INTERPOLATION"/>&apos;s profile.</source>
<target>Je staat op het punt een notitie toe te voegen aan het profiel van <x equiv-text="{{ registration.data()?.name }}" id="INTERPOLATION"/>.</target>
<target state="new">Je staat op het punt een notitie toe te voegen aan het profiel van <x equiv-text="{{ registrationName() }}" id="INTERPOLATION"/>.</target>
</trans-unit>
<trans-unit id="5190825892106392539" datatype="html">
<source>Spanish</source>
Expand Down Expand Up @@ -1464,7 +1464,7 @@
</trans-unit>
<trans-unit id="attribute-label-programFinancialServiceProviderConfigurationName" datatype="html">
<source>FSP</source>
<target>FSP</target>
<target state="new">FSP-configuratienaam</target>
</trans-unit>
<trans-unit id="attribute-label-referenceId" datatype="html">
<source>Reference ID</source>
Expand Down Expand Up @@ -1600,35 +1600,35 @@
</trans-unit>
<trans-unit id="export-changes" datatype="html">
<source>Status &amp; data changes</source>
<target>Status- en datawijzigingen</target>
<target state="new">Status- en datawijzigingen exporteren</target>
</trans-unit>
<trans-unit id="export-duplicate" datatype="html">
<source>Duplicate registrations</source>
<target>Duplicaten</target>
<target state="new">Duplicaten exporteren</target>
</trans-unit>
<trans-unit id="export-fsp-payment-list" datatype="html">
<source>Export FSP payment list</source>
<target>FSP-betalingslijst</target>
</trans-unit>
<trans-unit id="export-payments-debit-card-usage" datatype="html">
<source>Debit card usage</source>
<target>Visakaartgebruik</target>
<target state="new">Visakaartgebruik exporteren</target>
</trans-unit>
<trans-unit id="export-payments-last" datatype="html">
<source>Export last <x equiv-text="this.maxLastPaymentsNumber()" id="PH"/> payment(s)</source>
<target>Exporteer meest recente <x equiv-text="this.maxLastPaymentsNumber()" id="PH"/> betaling(en)</target>
</trans-unit>
<trans-unit id="export-payments-unused-vouchers" datatype="html">
<source>Unused vouchers</source>
<target>Ongebruikte vouchers</target>
<target state="new">Ongebruikte vouchers exporteren</target>
</trans-unit>
<trans-unit id="export-selected" datatype="html">
<source>Selected registrations</source>
<target>Geselecteerde registraties</target>
<target state="new">Geselecteerde registraties exporteren</target>
</trans-unit>
<trans-unit id="export-verification" datatype="html">
<source>Account number verification</source>
<target>Verifieer rekeningnummers</target>
<target state="new">Verifieer rekeningnummers</target>
</trans-unit>
<trans-unit id="generic-apply" datatype="html">
<source>Apply</source>
Expand Down Expand Up @@ -1905,11 +1905,11 @@
</trans-unit>
<trans-unit id="registration-full-name" datatype="html">
<source>Name</source>
<target>Naam</target>
<target state="new">Volledige naam</target>
</trans-unit>
<trans-unit id="registration-full-name-edit-info" datatype="html">
<source>This field is dynamically generated based on the other name fields available below:</source>
<target>Dit veld wordt dynamisch gegenereerd op basis van de andere naamvelden die hieronder beschikbaar zijn:</target>
<target state="new">Dit veld wordt dynamisch gegenereerd op basis van de andere naamvelden die hieronder beschikbaar zijn.</target>
</trans-unit>
<trans-unit id="registration-payments" datatype="html">
<source>Payments</source>
Expand Down Expand Up @@ -1964,8 +1964,8 @@
<target>Reset password</target>
</trans-unit>
<trans-unit id="retry-failed-transfers" datatype="html">
<source>Retry failed transfers</source>
<target>Mislukte transfers opnieuw proberen</target>
<source>Retry failed transfer(s)</source>
<target state="new">Mislukte transfers opnieuw proberen</target>
</trans-unit>
<trans-unit id="send-message" datatype="html">
<source>Send message</source>
Expand All @@ -1977,7 +1977,7 @@
</trans-unit>
<trans-unit id="table-clear-filters" datatype="html">
<source>Clear filters</source>
<target>Filters wissen</target>
<target state="new">Alle filters wissen</target>
</trans-unit>
<trans-unit id="table-quick-search" datatype="html">
<source>Filter by keyword</source>
Expand All @@ -1995,6 +1995,10 @@
<source>Pending</source>
<target>In behandeling</target>
</trans-unit>
<trans-unit id="retry-transfer" datatype="html">
<source>Retry transfer</source>
<target state="new">Retry transfer</target>
</trans-unit>
<trans-unit id="2218572265318708454" datatype="html">
<source>Registering</source>
<target state="new">Registering</target>
Expand Down Expand Up @@ -2033,4 +2037,4 @@
</trans-unit>
</body>
</file>
</xliff>
</xliff>
5 changes: 4 additions & 1 deletion interfaces/Portalicious/src/locale/messages.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -1178,7 +1178,7 @@
<source>You are about to retry <x equiv-text="{{ referenceIdsForRetryTransfers().length }}" id="INTERPOLATION"/> payment(s). The transfer status will change to Pending until received by the registration.</source>
</trans-unit>
<trans-unit id="retry-failed-transfers" datatype="html">
<source>Retry failed transfers</source>
<source>Retry failed transfer(s)</source>
</trans-unit>
<trans-unit id="payment-report" datatype="html">
<source>Payment report</source>
Expand Down Expand Up @@ -1525,6 +1525,9 @@
<trans-unit id="6891284064706667841" datatype="html">
<source>Enter reason</source>
</trans-unit>
<trans-unit id="retry-transfer" datatype="html">
<source>Retry transfer</source>
</trans-unit>
</body>
</file>
</xliff>

0 comments on commit 434205e

Please sign in to comment.