Skip to content

Commit

Permalink
Trigger bankDetails generation if not existing (#499)
Browse files Browse the repository at this point in the history
Closes FRONT-757
  • Loading branch information
bloodyowl authored Dec 14, 2023
1 parent c87fcf9 commit d67f24f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
22 changes: 21 additions & 1 deletion clients/banking/src/components/AccountArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { insets } from "@swan-io/lake/src/constants/insets";
import { useBoolean } from "@swan-io/lake/src/hooks/useBoolean";
import { usePersistedState } from "@swan-io/lake/src/hooks/usePersistedState";
import { useResponsive } from "@swan-io/lake/src/hooks/useResponsive";
import { useUrqlMutation } from "@swan-io/lake/src/hooks/useUrqlMutation";
import { noop } from "@swan-io/lake/src/utils/function";
import { isEmpty, isNotEmpty, isNullish } from "@swan-io/lake/src/utils/nullish";
import { useQueryWithErrorBoundary } from "@swan-io/lake/src/utils/urql";
Expand All @@ -34,7 +35,11 @@ import {
} from "react-native";
import { P, match } from "ts-pattern";
import logoSwan from "../assets/images/logo-swan.svg";
import { AccountAreaDocument, IdentificationLevelsFragment } from "../graphql/partner";
import {
AccountAreaDocument,
IdentificationLevelsFragment,
UpdateAccountLanguageDocument,
} from "../graphql/partner";
import { AccountActivationPage } from "../pages/AccountActivationPage";
import { AccountNotFoundPage, NotFoundPage } from "../pages/NotFoundPage";
import { ProfilePage } from "../pages/ProfilePage";
Expand Down Expand Up @@ -181,6 +186,21 @@ export const AccountArea = ({ accountMembershipId }: Props) => {
variables: { accountMembershipId },
});

const [, updateAccountLanguage] = useUrqlMutation(UpdateAccountLanguageDocument);

const accountId = accountMembership?.account?.id;
const language = accountMembership?.account?.language;
const iban = accountMembership?.account?.IBAN;
const bankDetails = accountMembership?.account?.bankDetails;

useEffect(() => {
// Triggers `bankDetails` generation if not yet available
if (accountId != null && language != null && iban != null && bankDetails == null) {
const future = updateAccountLanguage({ id: accountId, language });
return () => future.cancel();
}
}, [accountId, language, iban, bankDetails, updateAccountLanguage]);

const currentAccountMembership = useMemo(
() => Option.fromNullable(accountMembership).toResult(new Error("NoAccountMembership")),
[accountMembership],
Expand Down
14 changes: 14 additions & 0 deletions clients/banking/src/graphql/partner.gql
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ query AccountArea($accountMembershipId: ID!) {
id
...AccountMembership
account {
IBAN
bankDetails
language
id
paymentLevel
paymentAccountType
Expand Down Expand Up @@ -434,6 +437,17 @@ query AccountDetailsSettingsPage($accountId: ID!) {
}
}

mutation UpdateAccountLanguage($id: ID!, $language: AccountLanguage!) {
updateAccount(input: { accountId: $id, language: $language }) {
__typename
... on UpdateAccountSuccessPayload {
account {
id
}
}
}
}

mutation UpdateAccount(
$updateAccountInput: UpdateAccountInput!
$updateAccountHolderInput: UpdateAccountHolderInput!
Expand Down

0 comments on commit d67f24f

Please sign in to comment.