1 import { HttpTypes } from "@medusajs/types"
2 import { Alert, Button, Text } from "@medusajs/ui"
3 import { useState } from "react"
4 import { useTranslation } from "react-i18next"
5 import { getCountryProvinceObjectByIso2 } from "../../../../../lib/data/country-states"
6
7 type TaxRegionSublevelAlertProps = {
8 taxRegion: HttpTypes.AdminTaxRegion
9 showSublevelRegions: boolean
10 setShowSublevelRegions: (state: boolean) => void
11 }
12
13 export const TaxRegionSublevelAlert = ({
14 taxRegion,
15 showSublevelRegions,
16 setShowSublevelRegions,
17 }: TaxRegionSublevelAlertProps) => {
18 const { t } = useTranslation()
19
20 const [dismissed, setDismissed] = useState(false)
21 const provinceObject = getCountryProvinceObjectByIso2(taxRegion.country_code!)
22
23 if (
24 provinceObject ||
25 showSublevelRegions ||
26 dismissed ||
27 taxRegion.children.length
28 ) {
29 return null
30 }
31
32 return (
33 <Alert dismissible variant="info" className="bg-ui-bg-base">
34 <div className="flex flex-col gap-y-3">
35 <div className="flex flex-col">
36 <Text size="small" leading="compact" weight="plus" asChild>
37 <h2>{t("taxRegions.fields.sublevels.alert.header")}</h2>
38 </Text>
39 <Text size="small" leading="compact" className="text-pretty">
40 {t("taxRegions.fields.sublevels.alert.description")}
41 </Text>
42 </div>
43 <div className="flex items-center gap-x-3">
44 <Button
45 variant="secondary"
46 size="small"
47 onClick={() => setShowSublevelRegions(true)}
48 >
49 {t("taxRegions.fields.sublevels.alert.action")}
50 </Button>
51 <Button
52 variant="transparent"
53 size="small"
54 onClick={() => setDismissed(true)}
55 >
56 {t("actions.hide")}
57 </Button>
58 </div>
59 </div>
60 </Alert>
61 )
62 }