Skip to content

Commit

Permalink
Align add discount with rest links (#4958)
Browse files Browse the repository at this point in the history
* Align add discount with rest links

* Add changeset

* Remove not used component

* Add button link

* Add changeset

* Rm douplicated changeset
  • Loading branch information
poulch authored Jun 17, 2024
1 parent 04f51e5 commit cd0b03e
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/cool-boats-taste.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"saleor-dashboard": patch
---

You can now see Add discount align with rest of content
50 changes: 50 additions & 0 deletions src/components/ButtonLink/ButtonLink.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { Button, ButtonProps, vars } from "@saleor/macaw-ui-next";
import React from "react";

interface ButtonLinkProps extends ButtonProps {
children: React.ReactNode;
onClick?: React.MouseEventHandler;
underline?: boolean;
}

export const ButtonLink = ({
children,
disabled,
onClick,
underline,
...props
}: ButtonLinkProps) => {
const color = disabled ? vars.colors.text.defaultDisabled : vars.colors.text.accent1;

const handleClick = (event: React.MouseEvent) => {
if (disabled || !onClick) {
return;
}

onClick(event);
};

return (
<Button
variant="tertiary"
onClick={handleClick}
__backgroundColor="transparent"
textDecoration={{
default: underline ? "underline" : "none",
hover: "underline",
focus: "underline",
}}
cursor={disabled ? "not-allowed" : "pointer"}
style={{
textUnderlineOffset: vars.spacing[1],
padding: 0,
color,
fontWeight: 400,
textDecorationColor: color,
}}
{...props}
>
{children}
</Button>
);
};
1 change: 1 addition & 0 deletions src/components/ButtonLink/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./ButtonLink";
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-strict-ignore
import { ButtonLink } from "@dashboard/components/ButtonLink";
import HorizontalSpacer from "@dashboard/components/HorizontalSpacer";
import Link from "@dashboard/components/Link";
import Money from "@dashboard/components/Money";
import {
DiscountValueTypeEnum,
Expand All @@ -13,7 +13,7 @@ import { getFormErrors } from "@dashboard/utils/errors";
import getOrderErrorMessage from "@dashboard/utils/errors/order";
import { Typography } from "@material-ui/core";
import { makeStyles } from "@saleor/macaw-ui";
import { Box, Button, Popover, sprinkles } from "@saleor/macaw-ui-next";
import { Box, Popover, sprinkles } from "@saleor/macaw-ui-next";
import React from "react";
import { useIntl } from "react-intl";

Expand Down Expand Up @@ -123,26 +123,26 @@ const OrderDraftDetailsSummary: React.FC<OrderDraftDetailsSummaryProps> = props
};
const getShippingMethodComponent = () => {
if (hasChosenShippingMethod) {
return <Link onClick={onShippingMethodEdit}>{`${shippingMethodName}`}</Link>;
return <ButtonLink onClick={onShippingMethodEdit}>{`${shippingMethodName}`}</ButtonLink>;
}

const shippingCarrierBase = intl.formatMessage(messages.addShippingCarrier);

if (shippingAddress) {
return (
<Link onClick={onShippingMethodEdit} data-test-id="add-shipping-carrier">
<ButtonLink onClick={onShippingMethodEdit} data-test-id="add-shipping-carrier">
{shippingCarrierBase}
</Link>
</ButtonLink>
);
}

const addShippingAddressInfo = intl.formatMessage(messages.addShippingAddressInfo);

return (
<div className={classes.shippingMethodContainer}>
<Link underline disabled onClick={onShippingMethodEdit}>
<ButtonLink underline disabled onClick={onShippingMethodEdit}>
{shippingCarrierBase}
</Link>
</ButtonLink>
<HorizontalSpacer />
<Typography variant="caption">{`(${addShippingAddressInfo})`}</Typography>
</div>
Expand All @@ -156,9 +156,11 @@ const OrderDraftDetailsSummary: React.FC<OrderDraftDetailsSummaryProps> = props
<td>
<Popover open={isDialogOpen}>
<Popover.Trigger>
<Button variant="tertiary" onClick={isDialogOpen ? closeDialog : openDialog}>
<Link>{intl.formatMessage(discountTitle)}</Link>
</Button>
<Box>
<ButtonLink onClick={isDialogOpen ? closeDialog : openDialog}>
{intl.formatMessage(discountTitle)}
</ButtonLink>
</Box>
</Popover.Trigger>
<Popover.Content align="start" className={sprinkles({ zIndex: "3" })}>
<Box boxShadow="defaultOverlay">
Expand Down

0 comments on commit cd0b03e

Please sign in to comment.