-
Notifications
You must be signed in to change notification settings - Fork 212
Expand file tree
/
Copy pathindex.jsx
More file actions
67 lines (60 loc) · 2.24 KB
/
index.jsx
File metadata and controls
67 lines (60 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
* Copyright (c) 2024, Salesforce, Inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import React, {useContext} from 'react'
import PropTypes from 'prop-types'
import {FormattedMessage} from 'react-intl'
// Components
import {Box, Link} from '@salesforce/retail-react-app/app/components/shared/ui'
// Others
import {StoreLocatorContext} from '@salesforce/retail-react-app/app/components/store-locator-modal'
const StoreAvailabilityText = ({productInventories}) => {
const {selectedStore, isStoreSelected} = useContext(StoreLocatorContext)
const inStock =
selectedStore.inventoryId &&
Boolean(
productInventories?.find(
(inventory) => inventory.id === selectedStore.inventoryId && inventory.orderable
)
)
return (
<Box gap={1} fontWeight={400} display="flex">
{isStoreSelected ? (
<>
{inStock ? (
<FormattedMessage
id={'product_view.store_availability.in_stock_at'}
defaultMessage={'In Stock at'}
/>
) : (
<FormattedMessage
id={'product_view.store_availability.out_of_stock_at'}
defaultMessage={'Out of Stock at'}
/>
)}
<Link>{selectedStore.name}</Link>
</>
) : (
<>
<FormattedMessage
id={'product_view.store_availability.in_stock_at'}
defaultMessage={'In Stock at'}
/>
<Link>
<FormattedMessage
id={'product_view.link.select_store'}
defaultMessage={'Select Store'}
/>
</Link>
</>
)}
</Box>
)
}
StoreAvailabilityText.propTypes = {
productInventories: PropTypes.arrayOf(PropTypes.object)
}
export default StoreAvailabilityText