Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
@dotdev/reactive-click-and-collect
Advanced tools
This package provides a collection React Component which can be used to build a _Click and Collect_ feature.
This package provides a collection React Component which can be used to build a Click and Collect feature.
Internally it uses the @dotdev/reactive-google-map
for the embedded Google Map and miscellaneous Google API's for different geocoding and geolocation purposes.
This package is private and requires access to the @dotdev
organization to install.
yarn add @dotdev/reactive-click-and-collect
An example React Component is available in the EXAMPLE.md
file.
ClickAndCollect
ClassThe ClickAndCollect
class is responsible for initializing the Google API's and state management of all of the components which can be used.
If needed you can safely create multiple instances of the ClickAndCollect
class.
import { ClickAndCollect } from "@dotdev/reactive-click-and-collect";
const clickAndCollect = new ClickAndCollect({
endpoint: {
locations: "https://clickandcollect.foostore.com/api/locations",
stock: "https://clickandcollect.foostore.com/api/stock",
},
googleMapsApiKey: "...",
googleMapsApiVersion: "...",
formatData: (apiData) => ({ ... }),
});
The endpoint
property defines where the ClickAndCollect
component will go to look for locations and check stock.
The endpoint.locations
provided should accept a POST
request with the following JSON body structure:
{
"position": { // position used for 2d geospatial filter
"lat": 999,
"lng": 999,
},
"limit": 100, // maximum amount of results to return
"search": "Melbourne, Australia", // text search value (populated by ClickAndCollect.Search component with `autocomplete` turned off)
"query": {
"variantId": 222,
"inStock": true,
... // any additional information to filter the results (eg, variantId, inStock, storeType, etc...)
}
}
The endpoint will be called whenever the ClickAndCollect
state changes with the latest query information (eg, dragging the map, selecting and Autocomplete address).
To update the Query and more specifically the search
property, you can call the updateQuery()
method on a ClickAndCollect
instance, similar to React's setState()
method.
The endpoint.stock
provided should accept a POST
request with the following JSON body structure:
{
"location": "xxx", // refers to a `location.id` which is provided by the `endpoint.locations` endpoint
"items": [111, 222], // product variant id's
}
The endpoint can be called with the checkStock(...)
method on a ClickAndCollect
instance, if no location is provided it will try and use the currently selected location.
The endpoint should return the same structure as above, but the items
property should only contain items which are in stock.
import { ClickAndCollect } from "@dotdev/reactive-click-and-collect";
const clickAndCollect = new ClickAndCollect(...);
clickAndCollect.updateQuery({
search: {
variant: 9999,
},
});
ClickAndCollect.Provider
ComponentThis component implements the React.Context
API and exposes a Context Provider which expects an instance of ClickAndCollect
as a prop, other components provided by this package must be wrapped by the ClickAndCollect.Provider
component in order to maintain a consistent and stable state.
import { ClickAndCollect } from "@dotdev/reactive-click-and-collect";
const clickAndCollect = new ClickAndCollect(...);
const jsx = (
<ClickAndCollect.Provider
clickAndCollect={clickAndCollect}
>
<ClickAndCollect.Map ... />
<ClickAndCollect.List ... />
<ClickAndCollect.Search ... />
</ClickAndCollect.Provider>
)
ClickAndCollect.Map
ComponentThis component extends the GoogleMap
component from @dotdev/reactive-google-map
and will populate some of the props based on whats provided to the ClickAndCollect
class.
The props which are populated include:
googleMapsApiVersion
googleMapsApiKey
callback
mapOnClick
mapOnBoundsChange
markersOnClick
infowindowMaxWidth
infowindowOnClose
markers
You can override these props by providing your own, although it may be dangerous and cause unexpected behaviour.
Only one ClickAndCollect.Map
component can be used per ClickAndCollect instance.
import { ClickAndCollect } from "@dotdev/reactive-click-and-collect";
const clickAndCollect = new ClickAndCollect(...);
const jsx = (
<ClickAndCollect.Provider
clickAndCollect={clickAndCollect}
>
<ClickAndCollect.Map
style={{
width: "500px",
height: "500px",
}}
googleMapsOptions={{
center: {
lat: -37.8836542,
lng: 145.0140682,
},
zoom: 12,
maxZoom: 14,
zoomControl: true,
mapTypeControl: false,
scaleControl: false,
streetViewControl: false,
rotateControl: false,
fullscreenControl: false,
}}
/>
</ClickAndCollect.Provider>
)
ClickAndCollect.Search
ComponentThis component extends a simple HTMLInputElement
and updates the search
text value used by ClickAndCollect to query for results.
Optionally, if the autocomplete
prop is set to true, this component will extend the GoogleMapAutocomplete
component from @dotdev/reactive-google-map
and populate some of the props based on whats provided to the ClickAndCollect
class.
The props which are populated include:
googleMapsApiVersion
googleMapsApiKey
callback
onSelect
You can override these props by providing your own, although it may be dangerous and cause unexpected behaviour.
Only one ClickAndCollect.Search
component can be used per ClickAndCollect instance.
import { ClickAndCollect } from "@dotdev/reactive-click-and-collect";
const clickAndCollect = new ClickAndCollect(...);
const jsx = (
<ClickAndCollect.Provider
clickAndCollect={clickAndCollect}
>
<ClickAndCollect.Search
style={{
width: "400px",
}}
autocomplete={true}
/>
</ClickAndCollect.Provider>
)
ClickAndCollect.Geolocate
ComponentThis component implements the Geocoder
utility provided by @dotdev/reactive-google-map
.
When you click this component it will attempt to reverse geocode the users Postal Code with the Geolocation Web API, it expects a function to be provided as it's children
prop and exposes a loading
argument which can be used to determine if geolocation is in progress.
import { ClickAndCollect } from "@dotdev/reactive-click-and-collect";
const clickAndCollect = new ClickAndCollect(...);
const jsx = (
<ClickAndCollect.Provider
clickAndCollect={clickAndCollect}
>
<ClickAndCollect.Geolocate
style={{
width: "400px",
}}
>
{(loading) => (
<span>{loading ? "Locating..." : "Geolocate!"}</span>
)}
</ClickAndCollect.Geolocate>
</ClickAndCollect.Provider>
)
ClickAndCollect.List
ComponentThis component exposes a simple child-iterator to render out a list of the available locations.
import { ClickAndCollect } from "@dotdev/reactive-click-and-collect";
const clickAndCollect = new ClickAndCollect(...);
const jsx = (
<ClickAndCollect.Provider
clickAndCollect={clickAndCollect}
>
<ul>
<ClickAndCollect.List>
{(marker, selected) => (
<li key={marker.id}>
<span>Marker {marker.id}</span><br />
<span onClick={() => clickAndCollect.selectMarker(marker)}>Select</span><br />
<a href={Geocoder.latLngToDirections(marker.position)} target="_blank">Directions</a>
</li>
)}
</ClickAndCollect.List>
</ul>
</ClickAndCollect.Provider>
)
Git management follows the standard Git Flow ideology.
Package for usage:
yarn run package
Package during development, with rebuild on file change:
yarn run package --watch
Lint before commiting:
yarn run lint
Generate reference documentation:
yarn run docs
FAQs
This package provides a collection React Component which can be used to build a _Click and Collect_ feature.
The npm package @dotdev/reactive-click-and-collect receives a total of 0 weekly downloads. As such, @dotdev/reactive-click-and-collect popularity was classified as not popular.
We found that @dotdev/reactive-click-and-collect demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 17 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.