Skip to content

Commit

Permalink
feat: Checkout Summary allow Tooltip for disabled buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
gmolki committed Oct 24, 2024
1 parent 4a00379 commit e6be0b0
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 31 deletions.
5 changes: 4 additions & 1 deletion src/components/form/CheckoutSummary/cmp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -250,13 +250,15 @@ export const CheckoutSummary = ({
domains,
description,
button: buttonNode,
footerButton = buttonNode,
control,
receiverAddress,
paymentMethod,
website,
mainRef,
isPersistent = type === EntityType.Instance,
disablePaymentMethod = true,
disabledStreamTooltip,
onSwitchPaymentMethod,
}: // streamDuration,
CheckoutSummaryProps) => {
Expand Down Expand Up @@ -289,6 +291,7 @@ CheckoutSummaryProps) => {
disabledHold={disabledHold}
disabledStream={disabledStream}
onSwitch={onSwitchPaymentMethod}
disabledStreamTooltip={disabledStreamTooltip}
/>
)

Expand All @@ -298,7 +301,7 @@ CheckoutSummaryProps) => {
<CheckoutSummaryFooter
{...{
paymentMethod,
submitButton: buttonNode,
submitButton: footerButton,
paymentMethodSwitch: paymentMethodSwitchNode,
mainRef,
totalCost: cost?.totalCost,
Expand Down
2 changes: 2 additions & 0 deletions src/components/form/CheckoutSummary/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ export type CheckoutSummaryProps = {
volumes?: VolumeField[]
domains?: DomainField[]
button?: ReactNode
footerButton?: ReactNode
description?: ReactNode
mainRef?: RefObject<HTMLElement>
paymentMethod: PaymentMethod
control?: Control
receiverAddress?: string
streamDuration?: StreamDurationField
disablePaymentMethod?: boolean
disabledStreamTooltip?: ReactNode
onSwitchPaymentMethod?: (e: PaymentMethod) => void
}

Expand Down
70 changes: 46 additions & 24 deletions src/components/form/SelectPaymentMethod/cmp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,64 @@ import { Switch } from '@aleph-front/core'
import { SelectPaymentMethodProps } from './types'
import { useSelectPaymentMethod } from '@/hooks/form/useSelectPaymentMethod'
import { StyledLabel } from './styles'
import { PaymentMethod } from '@/helpers/constants'
import ResponsiveTooltip from '@/components/common/ResponsiveTooltip'

export const SelectPaymentMethod = (props: SelectPaymentMethodProps) => {
const {
disabledHold,
disabledStream,
paymentMethodCtrl,
disabledStreamTooltip,
switchRef,
selectedPaymentMethod,
handleClickHold,
handleClickStream,
} = useSelectPaymentMethod(props)

return (
<div tw="flex items-center justify-center gap-4" className="tp-body3">
<StyledLabel
{...{
onClick: handleClickHold,
$disabled: disabledHold,
}}
<>
<div
tw="flex items-center justify-center gap-4"
className="tp-body3"
ref={switchRef}
>
Hold tokens
</StyledLabel>
<Switch
{...{
...paymentMethodCtrl.field,
...paymentMethodCtrl.fieldState,
disabled: disabledHold || disabledStream,
}}
/>
<StyledLabel
{...{
onClick: handleClickStream,
$disabled: disabledStream,
}}
>
Pay-as-you-go
</StyledLabel>
</div>
<StyledLabel
{...{
onClick: handleClickHold,
$selected: selectedPaymentMethod === PaymentMethod.Hold,
$disabled: disabledHold,
}}
>
Hold tokens
</StyledLabel>
<Switch
{...{
...paymentMethodCtrl.field,
...paymentMethodCtrl.fieldState,
disabled: disabledHold || disabledStream,
}}
ref={switchRef}
/>
<StyledLabel
{...{
onClick: handleClickStream,
$selected: selectedPaymentMethod === PaymentMethod.Stream,
$disabled: disabledStream,
}}
>
Pay-as-you-go
</StyledLabel>
</div>
{disabledStream && (
<ResponsiveTooltip
my="bottom-left"
at="center-center"
targetRef={switchRef as React.RefObject<HTMLButtonElement>}
content={disabledStreamTooltip}
/>
)}
</>
)
}

Expand Down
9 changes: 3 additions & 6 deletions src/components/form/SelectPaymentMethod/styles.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import tw from 'twin.macro'
import styled, { css } from 'styled-components'

export type StyledLabelProps = { $disabled?: boolean }
export type StyledLabelProps = { $selected?: boolean; $disabled?: boolean }

export const StyledLabel = styled.label<StyledLabelProps>`
${({ $disabled = false }) => css`
/* ${tw`cursor-pointer`} */
/* @todo: fix it after supporting stream payment with automatic allocation or hold payment with manual allocation */
${tw`cursor-not-allowed`}
${({ $selected = false, $disabled = false }) => css`
${$disabled ? tw`cursor-not-allowed` : !$selected ? tw`cursor-pointer` : ''}
${$disabled &&
css`
${tw`opacity-40 cursor-not-allowed`}
Expand Down

0 comments on commit e6be0b0

Please sign in to comment.