2022-03-09 08:56:55 +00:00
|
|
|
import { useGiftCardProductsCountQuery } from "@saleor/graphql";
|
2021-09-22 06:45:24 +00:00
|
|
|
import { Alert } from "@saleor/macaw-ui";
|
|
|
|
import React from "react";
|
|
|
|
import { useIntl } from "react-intl";
|
|
|
|
|
|
|
|
import { giftCardsListHeaderMenuItemsMessages as messages } from "../messages";
|
|
|
|
import GiftCardsListHeaderAlertContent from "./GiftCardsListHeaderAlertContent";
|
|
|
|
|
|
|
|
const GiftCardsListHeaderAlert: React.FC = () => {
|
|
|
|
const intl = useIntl();
|
|
|
|
|
|
|
|
const {
|
|
|
|
data: giftCardProductsCount,
|
2022-06-21 09:36:55 +00:00
|
|
|
loading: giftCardProductsCountLoading,
|
2021-09-22 06:45:24 +00:00
|
|
|
} = useGiftCardProductsCountQuery();
|
|
|
|
|
|
|
|
const giftCardProductTypesExist =
|
|
|
|
giftCardProductsCount?.giftCardProductTypes.totalCount > 0;
|
|
|
|
const giftCardProductsExist =
|
|
|
|
giftCardProductsCount?.giftCardProducts.totalCount > 0;
|
|
|
|
|
|
|
|
const showNoGiftCardProductsAlert =
|
|
|
|
!giftCardProductsCountLoading &&
|
|
|
|
(!giftCardProductTypesExist || !giftCardProductsExist);
|
|
|
|
|
|
|
|
if (showNoGiftCardProductsAlert) {
|
|
|
|
return (
|
|
|
|
<Alert
|
|
|
|
title={intl.formatMessage(messages.noGiftCardsAlertTitle)}
|
|
|
|
variant="warning"
|
|
|
|
close={false}
|
|
|
|
>
|
|
|
|
<GiftCardsListHeaderAlertContent
|
|
|
|
giftCardProductTypesExist={giftCardProductTypesExist}
|
|
|
|
giftCardProductsExist={giftCardProductsExist}
|
|
|
|
/>
|
|
|
|
</Alert>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default GiftCardsListHeaderAlert;
|