|
1
|
import { HttpTypes } from "@medusajs/types" |
|
2
|
import { UIMatch } from "react-router-dom" |
|
3
|
|
|
4
|
import { useTaxRegion } from "../../../hooks/api" |
|
5
|
import { |
|
6
|
getProvinceByIso2, |
|
7
|
isProvinceInCountry, |
|
8
|
} from "../../../lib/data/country-states" |
|
9
|
|
|
10
|
type TaxRegionDetailBreadcrumbProps = UIMatch<HttpTypes.AdminTaxRegionResponse> |
|
11
|
|
|
12
|
export const TaxRegionDetailBreadcrumb = ( |
|
13
|
props: TaxRegionDetailBreadcrumbProps |
|
14
|
) => { |
|
15
|
const { province_id } = props.params || {} |
|
16
|
|
|
17
|
const { tax_region } = useTaxRegion(province_id!, undefined, { |
|
18
|
initialData: props.loaderData, |
|
19
|
enabled: Boolean(province_id), |
|
20
|
}) |
|
21
|
|
|
22
|
if (!tax_region) { |
|
23
|
return null |
|
24
|
} |
|
25
|
|
|
26
|
const countryCode = tax_region.country_code?.toUpperCase() |
|
27
|
const provinceCode = tax_region.province_code?.toUpperCase() |
|
28
|
|
|
29
|
const isValid = isProvinceInCountry(countryCode, provinceCode) |
|
30
|
|
|
31
|
return <span>{isValid ? getProvinceByIso2(provinceCode) : provinceCode}</span> |
|
32
|
} |
|
33
|
|
|
34
|
export const seo = (match: UIMatch<HttpTypes.AdminTaxRegionResponse>) => { |
|
35
|
const taxRegion = match.loaderData?.tax_region |
|
36
|
|
|
37
|
if (!taxRegion) { |
|
38
|
return { title: undefined } |
|
39
|
} |
|
40
|
|
|
41
|
const countryCode = taxRegion.country_code?.toUpperCase() |
|
42
|
const provinceCode = taxRegion.province_code?.toUpperCase() |
|
43
|
const isValid = isProvinceInCountry(countryCode, provinceCode) |
|
44
|
|
|
45
|
return { title: isValid ? getProvinceByIso2(provinceCode) : provinceCode } |
|
46
|
} |