Skip to content

Commit

Permalink
fix filter
Browse files Browse the repository at this point in the history
  • Loading branch information
sandrine-ds committed Nov 20, 2024
1 parent 27ddcb9 commit e73c520
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 45 deletions.
65 changes: 29 additions & 36 deletions clients/banking/src/components/MerchantProfilePaymentArea.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AsyncData, Result } from "@swan-io/boxed";
import { AsyncData, Option, Result } from "@swan-io/boxed";
import { Link } from "@swan-io/chicane";
import { useQuery } from "@swan-io/graphql-client";
import { Box } from "@swan-io/lake/src/components/Box";
Expand All @@ -13,12 +13,12 @@ import { Space } from "@swan-io/lake/src/components/Space";
import { LinkConfig } from "@swan-io/lake/src/components/VirtualizedList";
import { spacings } from "@swan-io/lake/src/constants/design";
import { nullishOrEmptyToUndefined } from "@swan-io/lake/src/utils/nullish";
import { useCallback, useMemo, useRef, useState } from "react";
import { useCallback, useRef, useState } from "react";
import { StyleSheet } from "react-native";
import { match, P } from "ts-pattern";
import {
MerchantPaymentFiltersInput,
MerchantPaymentFragment,
MerchantPaymentMethodType,
MerchantPaymentsDocument,
} from "../graphql/partner";
import { t } from "../utils/i18n";
Expand All @@ -45,6 +45,12 @@ const styles = StyleSheet.create({

const PER_PAGE = 20;

const ALLOWED_PAYMENT_METHODS = new Set<MerchantPaymentMethodType>([
"Card",
"SepaDirectDebitB2b",
"SepaDirectDebitCore",
]);

type Props = {
params: GetRouteParams<"AccountMerchantsProfilePaymentsArea">;
large: boolean;
Expand All @@ -58,17 +64,9 @@ export const MerchantProfilePaymentArea = ({ params, large }: Props) => {
"AccountMerchantsProfilePaymentsDetails",
]);

const filters: MerchantPaymentFiltersInput = useMemo(() => {
return {
status: params.status,
search: nullishOrEmptyToUndefined(params.search),
} as const;
}, [params]);

const [data, { isLoading, reload, setVariables }] = useQuery(MerchantPaymentsDocument, {
merchantProfileId,
first: PER_PAGE,
filters,
});

const panelRef = useRef<FocusTrapRef | null>(null);
Expand Down Expand Up @@ -100,16 +98,29 @@ export const MerchantProfilePaymentArea = ({ params, large }: Props) => {

const search = nullishOrEmptyToUndefined(params.search);

const shouldEnableNewButton = data
.toOption()
.flatMap(result => result.toOption())
.flatMap(({ merchantProfile }) => Option.fromNullable(merchantProfile))
.map(merchant => {
const paymentMethods = merchant.merchantPaymentMethods ?? [];
return paymentMethods.some(
paymentMethod =>
ALLOWED_PAYMENT_METHODS.has(paymentMethod.type) &&
paymentMethod.statusInfo.status === "Enabled",
);
});

return (
<>
{!large && (
<Box style={styles.containerMobile} alignItems="stretch">
<LakeTooltip
content={t("merchantProfile.paymentLink.button.new.disable")} //TODO
// disabled={shouldEnableNewButton !== Option.Some(false)}
content={t("merchantProfile.paymentLink.button.new.disable")}
disabled={shouldEnableNewButton !== Option.Some(false)}
>
<LakeButton
// disabled={!shouldEnableNewButton.getOr(false)}
disabled={!shouldEnableNewButton.getOr(false)}
size="small"
icon="add-circle-filled"
color="current"
Expand All @@ -121,7 +132,7 @@ export const MerchantProfilePaymentArea = ({ params, large }: Props) => {
})
}
>
{t("merchantProfile.payments.button.new")} //TODO
{t("merchantProfile.paymentLink.button.new")}
</LakeButton>
</LakeTooltip>
</Box>
Expand All @@ -135,11 +146,11 @@ export const MerchantProfilePaymentArea = ({ params, large }: Props) => {
{large && (
<>
<LakeTooltip
content={t("merchantProfile.paymentLink.button.new.disable")} //TODO
// disabled={shoul={shouldEnableNewButton !== Option.Some(false)}
content={t("merchantProfile.paymentLink.button.new.disable")}
disabled={shouldEnableNewButton !== Option.Some(false)}
>
<LakeButton
// disabled={!shouldEnableNewButton.getOr(false)}
disabled={!shouldEnableNewButton.getOr(false)}
size="small"
icon="add-circle-filled"
color="current"
Expand All @@ -156,24 +167,6 @@ export const MerchantProfilePaymentArea = ({ params, large }: Props) => {
</LakeTooltip>
{/* // TODO USE FILL */}
<Space width={12} />

<LakeButton
// disabled={!shouldEnableNewButton.getOr(false)}
size="small"
mode="secondary"
onPress={
() => {}
// Router.push("AccountMerchantsProfilePaymentLinkList", {
// new: "true",
// accountMembershipId,
// merchantProfileId,
// })
}
>
{t("merchantProfile.payments.button.refund")}
</LakeButton>

<Space width={12} />
</>
)}

Expand Down
13 changes: 6 additions & 7 deletions clients/banking/src/components/MerchantProfilePaymentDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,19 +194,18 @@ export const MerchantProfilePaymentDetail = ({ paymentLinkId, paymentId, large }
)}
/>

<LakeLabel
{/* <LakeLabel
type="view"
label={t("merchantProfile.payments.details.chargebackBalance")}
render={() => (
<LakeText variant="regular" color={colors.gray[900]}>
TODO
{/* {formatCurrency(
Number(payment.balance.availableToCancel.value),
payment.balance.availableToCancel.currency,
)} */}
{formatCurrency(
Number(payment.balance.chargebackBalance.value),
payment.balance.chargebackBalance.currency,
)}
</LakeText>
)}
/>
/> */}

<LakeLabel
type="view"
Expand Down
11 changes: 9 additions & 2 deletions clients/banking/src/graphql/partner.gql
Original file line number Diff line number Diff line change
Expand Up @@ -2336,14 +2336,21 @@ fragment MerchantPaymentsConnection on MerchantPaymentConnection {

query MerchantPayments(
$merchantProfileId: ID!
$filters: MerchantPaymentFiltersInput!
# $filters: MerchantPaymentFiltersInput!
$first: Int!
$after: String
) {
merchantProfile(id: $merchantProfileId) {
merchantPayments(filters: $filters, first: $first, after: $after) {
merchantPayments(first: $first, after: $after) {
...MerchantPaymentsConnection
}
merchantPaymentMethods {
id
type
statusInfo {
status
}
}
}
}

Expand Down

0 comments on commit e73c520

Please sign in to comment.