Skip to content

Commit e23354a

Browse files
committed
Format account creation attempt notifications
1 parent b08ac82 commit e23354a

File tree

7 files changed

+120
-21
lines changed

7 files changed

+120
-21
lines changed

daikoku/app/controllers/LoginController.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ class LoginController(
518518
)
519519
),
520520
state = SubscriptionDemandState.Waiting,
521-
value = body,
521+
value = body - "confirmPassword" - "password",
522522
fromTenant = ctx.tenant.id
523523
)
524524
)

daikoku/app/domain/SchemaDefinition.scala

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,14 @@ object SchemaDefinition {
646646
ListType(StringType),
647647
resolve = ctx => ctx.value.emails
648648
)
649+
),
650+
AddFields(
651+
Field(
652+
"type",
653+
StringType,
654+
description = Some("Type of the validation step"),
655+
resolve = ctx => ctx.value.name
656+
)
649657
)
650658
)
651659
)
@@ -667,6 +675,14 @@ object SchemaDefinition {
667675
ReplaceField(
668676
"team",
669677
Field("team", StringType, resolve = ctx => ctx.value.team.value)
678+
),
679+
AddFields(
680+
Field(
681+
"type",
682+
StringType,
683+
description = Some("Type of the validation step"),
684+
resolve = ctx => ctx.value.name
685+
)
670686
)
671687
)
672688
)
@@ -700,6 +716,14 @@ object SchemaDefinition {
700716
OptionType(StringType),
701717
resolve = ctx => ctx.value.formatter
702718
)
719+
),
720+
AddFields(
721+
Field(
722+
"type",
723+
StringType,
724+
description = Some("Type of the validation step"),
725+
resolve = ctx => ctx.value.name
726+
)
703727
)
704728
)
705729
)
@@ -725,6 +749,14 @@ object SchemaDefinition {
725749
ReplaceField(
726750
"headers",
727751
Field("headers", MapType, resolve = _.value.headers)
752+
),
753+
AddFields(
754+
Field(
755+
"type",
756+
StringType,
757+
description = Some("Type of the validation step"),
758+
resolve = ctx => ctx.value.name
759+
)
728760
)
729761
)
730762
)
@@ -750,6 +782,14 @@ object SchemaDefinition {
750782
StringType,
751783
resolve = ctx => ctx.value.thirdPartyPaymentSettingsId.value
752784
)
785+
),
786+
AddFields(
787+
Field(
788+
"type",
789+
StringType,
790+
description = Some("Type of the validation step"),
791+
resolve = ctx => ctx.value.name
792+
)
753793
)
754794
)
755795
)
@@ -2976,7 +3016,7 @@ object SchemaDefinition {
29763016
),
29773017
ReplaceField("state", Field("state", StringType, resolve = _.value.state.name)),
29783018
ReplaceField("fromTenant", Field("fromTenant", StringType, resolve = _.value.fromTenant.value)),
2979-
ReplaceField("value", Field("value", JsonType, resolve = _.value.value)),
3019+
ReplaceField("value", Field("value", JsonType, resolve = _.value.value - "password" - "confirmPassword")),
29803020
ReplaceField("metadata", Field("metadata", MapType, resolve = _.value.metadata)),
29813021
)
29823022
lazy val AccountCreationAttemptType = new PossibleObject(

daikoku/javascript/src/components/backoffice/apis/SubscriptionProcessEditor.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ type ValidationStepProps = {
149149

150150
const ValidationStep = (props: ValidationStepProps) => {
151151
const step = props.step;
152+
console.debug(step)
152153

153154
switch (step.type) {
154155
case 'payment':

daikoku/javascript/src/components/backoffice/notifications/NotificationList.tsx

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
import { useInfiniteQuery, useQuery, useQueryClient } from '@tanstack/react-query';
2-
import { ColumnFiltersState, createColumnHelper, flexRender, getCoreRowModel, getSortedRowModel, PaginationState, SortingState, useReactTable } from '@tanstack/react-table';
2+
import { ColumnFiltersState, createColumnHelper, flexRender, getCoreRowModel, getSortedRowModel, PaginationState, useReactTable } from '@tanstack/react-table';
33
import classNames from 'classnames';
44
import { formatDistanceToNow } from 'date-fns';
55
import { useContext, useEffect, useMemo, useState } from 'react';
66
import Select, { components, MultiValue, OptionProps, ValueContainerProps } from 'react-select';
77

88
import { constraints, format, type } from '@maif/react-forms';
9-
import { Link, useNavigate, useSearchParams } from 'react-router-dom';
9+
import { useSearchParams } from 'react-router-dom';
1010
import { I18nContext, ModalContext, TranslateParams } from '../../../contexts';
1111
import { GlobalContext } from '../../../contexts/globalContext';
1212
import { CustomSubscriptionData } from '../../../contexts/modals/SubscriptionMetadataModal';
1313
import * as Services from '../../../services';
14-
import { DaikokuMode, Display, IAccountCreationGQL, IApi, IApiGQL, IApiPost, IIssuesTag, isError, Issue, ISubscription, ISubscriptionDemand, ISubscriptionDemandGQL, ITeamFullGql, ITeamSimple, ITenant, ITesting, IUsagePlan, IUser, IValidationStepPayment } from '../../../types';
14+
import { IAccountCreationGQL, IApiGQL, IApiPost, isError, Issue, ISubscription, ISubscriptionDemandGQL, ITeamFullGql, ITeamSimple, ITenant, IUsagePlan, IUser, IValidationStep } from '../../../types';
1515
import { getLanguageFns, Spinner } from '../../utils';
1616
import { FeedbackButton } from '../../utils/FeedbackButton';
17-
import { Option as opt } from '../../utils';
18-
import { IApiSubscriptionGql } from '../apis';
1917
import { SimpleApiKeyCard } from '../apikeys/TeamApiKeysForApi';
18+
import { IApiSubscriptionGql } from '../apis';
2019
declare module '@tanstack/react-table' {
2120
interface ColumnMeta<TData extends unknown, TValue> extends NotificationColumnMeta { }
2221
}
@@ -170,7 +169,7 @@ type NotificationActionGQL =
170169
| {
171170
__typename: 'CheckoutForSubscription';
172171
plan: IUsagePlan;
173-
step: IValidationStepPayment;
172+
step: IValidationStep & { type: 'payment' };
174173
demand: ISubscriptionDemandGQL;
175174
api: IApiGQL;
176175
}
@@ -779,7 +778,7 @@ export const NotificationList = () => {
779778
return translate({ key: 'notif.apikey.deletion' })
780779
case 'ApiKeyDeletionInformationV2': {
781780
const apiKeyDeletionInformationDescription = translate({ key: 'notif.apikey.deletion' })
782-
const __subscription = notification.action.subscription
781+
const __subscription = notification.action.subscription
783782
return (
784783
<>
785784
{apiKeyDeletionInformationDescription}
@@ -810,7 +809,7 @@ export const NotificationList = () => {
810809
const __api = notification.action.api
811810
const __plan = notification.action.plan
812811
const __team = notification.action.api.team
813-
const __subscription = notification.action.subscription
812+
const __subscription = notification.action.subscription
814813
return (
815814
<>
816815
{apiKeyRotationInProgressDescription}
@@ -836,11 +835,11 @@ export const NotificationList = () => {
836835
case 'ApiKeyRotationEnded':
837836
return translate('notif.apikey.rotation.ended')
838837
case 'ApiKeyRotationEndedV2': {
839-
const apiKeyRotationEndedV2Description = translate('notif.apikey.rotation.ended')
838+
const apiKeyRotationEndedV2Description = translate('notif.apikey.rotation.ended')
840839
const __api = notification.action.api
841840
const __plan = notification.action.plan
842841
const __team = notification.action.api.team
843-
const __subscription = notification.action.subscription
842+
const __subscription = notification.action.subscription
844843
return <>
845844
{apiKeyRotationEndedV2Description}
846845
<a
@@ -868,7 +867,7 @@ export const NotificationList = () => {
868867
const __api = notification.action.api
869868
const __plan = notification.action.plan
870869
const __team = notification.action.api.team
871-
const __subscription = notification.action.subscription
870+
const __subscription = notification.action.subscription
872871
return <>
873872
{apiKeyRefreshV2Description}
874873
<a
@@ -920,11 +919,42 @@ export const NotificationList = () => {
920919
return translate('notif.issues.comment')
921920
case 'ApiSubscriptionTransferSuccess':
922921
return translate('notif.subscription.transfer.success')
923-
case 'AccountCreationAttempt':
924-
return translate('notif.account.creation.attempt');
922+
case 'AccountCreationAttempt':
923+
const description = translate('notif.account.creation.attempt');
924+
const value = notification.action.demand.value
925+
const formStep = notification.action.demand.steps.map(s => s.step).find(s => s.type === 'form')
926+
927+
const regexp = /\[\[(.+?)\]\]/g;
928+
const matches = formStep?.formatter.match(regexp);
929+
930+
const formattedValue = matches?.reduce((acc, match) => {
931+
const key = match.replace('[[', '').replace(']]', '');
932+
return acc.replace(match, value[key] || match);
933+
}, formStep?.formatter ?? "");
934+
935+
return (
936+
<>
937+
{description}
938+
<a
939+
href='#'
940+
className='underline'
941+
aria-label={translate('notifications.page.account.creation.attempt.detail.button.label')}
942+
title={translate('notifications.page.account.creation.attempt.detail.button.label')}
943+
onClick={() => alert({
944+
title: translate('notifications.page.account.creation.attempt.detail.modal.title'),
945+
message: <div>
946+
{!!formattedValue && <em>{formattedValue}</em>}
947+
<pre>
948+
{JSON.stringify(value, null, 2)}
949+
</pre>
950+
</div>
951+
})}>
952+
<span className='ms-2'>[{translate('notifications.page.account.creation.attempt.detail.button.label')}]</span>
953+
</a>
954+
</>
955+
)
925956
default:
926957
return '';
927-
928958
}
929959
}
930960

@@ -1024,10 +1054,8 @@ export const NotificationList = () => {
10241054
meta: { className: "description-cell" },
10251055
cell: (info) => {
10261056
return <div className='notification d-flex align-items-center gap-3'>
1027-
<div>
1028-
<div className='notification__description'>
1029-
{notificationFormatter(info.row.original, translate, tenant)}
1030-
</div>
1057+
<div className='notification__description'>
1058+
{notificationFormatter(info.row.original, translate, tenant)}
10311059
</div>
10321060
</div>;
10331061
},

daikoku/javascript/src/locales/en/translation.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,6 +1648,8 @@
16481648
"notifications.page.table.header.label.sender": "Sender",
16491649
"notifications.page.table.header.label.date": "Date",
16501650
"notifications.page.table.header.label.actions": "Actions",
1651+
"notifications.page.account.creation.attempt.detail.button.label": "Show more",
1652+
"notifications.page.account.creation.attempt.detail.modal.title": "Account creation attempt details",
16511653
"tenant.edit.clientNamePattern.label": "Custom client name pattern",
16521654
"tenant.edit.clientNamePattern.help": "This pattern is used to customize the client name when creating an API key. The string can include dynamic values using the ${my.value} syntax.",
16531655
"tenant.edit.clientNamePattern.help2": "The following values are available:",

daikoku/javascript/src/locales/fr/translation.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1649,7 +1649,9 @@
16491649
"notifications.page.table.header.label.sender": "Source",
16501650
"notifications.page.table.header.label.date": "Date",
16511651
"notifications.page.table.header.label.actions": "Actions",
1652-
"tenant.edit.clientNamePattern.label": "Modèle de nom de client personnalisé",
1652+
"notifications.page.account.creation.attempt.detail.button.label": "Voir plus",
1653+
"notifications.page.account.creation.attempt.detail.modal.title": "Détail de la demande de création de compte",
1654+
"tenant.edit.clientNamePattern.label" : "Modèle de nom de client personnalisé",
16531655
"tenant.edit.clientNamePattern.help": "Ce modèle est utilisé pour personnaliser le nom du client lors de la création d'une clé d'API. La chaîne de caractères peut contenir des valeurs dynamiques en utilisant la syntaxe ${ma.valeur}.",
16541656
"tenant.edit.clientNamePattern.help2": "Les valeurs disponibles sont les suivantes :",
16551657
"tenant.security.account.creation.process.button.label": "Personnaliser le processus de création de comptes",

daikoku/javascript/src/services/index.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2038,6 +2038,32 @@ export const graphql = {
20382038
_id
20392039
email
20402040
name
2041+
value
2042+
steps {
2043+
step {
2044+
... on Form {
2045+
__typename
2046+
formatter
2047+
type
2048+
}
2049+
... on Email {
2050+
__typename
2051+
type
2052+
}
2053+
... on TeamAdmin {
2054+
__typename
2055+
type
2056+
}
2057+
... on Payment {
2058+
__typename
2059+
type
2060+
}
2061+
... on HttpRequest {
2062+
__typename
2063+
type
2064+
}
2065+
}
2066+
}
20412067
}
20422068
motivation
20432069
}

0 commit comments

Comments
 (0)