Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev/add chatbot #13

Draft
wants to merge 14 commits into
base: master
Choose a base branch
from
28 changes: 28 additions & 0 deletions .github/workflows/pr-to-s3.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: PR Deploy
on:
pull_request:
branches: [ master ]
workflow_dispatch:

jobs:
pr-deploy:
if: "!contains(github.event.head_commit.message, 'skip ci')"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node
- run: npm ci
- run: npm run build
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: eu-central-1
- name: Deploy static site to S3 bucket
run: aws s3 sync dist s3://demo.woosmap.com/storelocator/mapjs/pr-${{ github.event.pull_request.number }}/ --acl public-read
111 changes: 104 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"@typescript-eslint/eslint-plugin": "^6.20.0",
"@typescript-eslint/parser": "^6.20.0",
"cypress": "^13.6.4",
"deep-chat": "^2.0.1",
"jest": "29.7.0",
"jest-environment-jsdom": "29.7.0",
"lint-staged": "^15.2.1",
Expand Down
51 changes: 49 additions & 2 deletions src/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import StoresListComponent, {StoresListComponentEvents} from "./components/store
import "./styles/main.scss";
import FilterComponent, {FilterComponentEvents} from "./components/filter/filter";
import DirectionsComponent, {DirectionsComponentEvents, IDirections} from "./components/directions/directions";
import ChatbotComponent, {ChatbotComponentEvents} from "./components/chatbot/chatbot";
import {setUserLocale, SYSTEM_LANG} from './helpers/locale';
import {debounce} from "./utils/utils";
import {Configuration, getConfig, setConfig} from "./configuration/config";
Expand Down Expand Up @@ -38,6 +39,7 @@ export default class StoreLocator extends Component<IStoreLocator> {
public storesListComponent!: StoresListComponent;
public storeDetailsComponent!: StoreDetailsComponent;
public filterComponent!: FilterComponent;
public chatbotComponent!: ChatbotComponent;
private $sidebarContentContainer!: HTMLElement;
private urlParameterManager!: URLParameterManager<AllowedParameters>;
private userLocationMarker!: woosmap.map.Marker | null;
Expand Down Expand Up @@ -104,6 +106,12 @@ export default class StoreLocator extends Component<IStoreLocator> {
store: undefined
},
});
this.chatbotComponent = new ChatbotComponent({
$target: document.getElementById(
getConfig().selectors.chatContainerID
) as HTMLElement,
initialState: {},
});
if (getConfig().search.availableServices.length) {
this.filterComponent = new FilterComponent({
$target: document.getElementById(
Expand Down Expand Up @@ -132,6 +140,44 @@ export default class StoreLocator extends Component<IStoreLocator> {
this.setListView();
}
);
[ChatbotComponentEvents.FIND_NEARBY_STORES, ChatbotComponentEvents.MOVE_MAP].forEach(event => {
this.chatbotComponent.on(event, (locality?: SearchLocation) => {
this.directionsComponent.emit(DirectionsComponentEvents.CLOSE_DIRECTIONS)
if (locality) {
this.searchComponent.setState({selectedLocality: locality}, true, () => {
this.searchComponent.selectLocality();
})
} else {
const centerLatLng = this.mapComponent.map.getCenter().toJSON()
locality = {
name: `${centerLatLng.lat}, ${centerLatLng.lng}`,
location: {
lat: centerLatLng.lat,
lng: centerLatLng.lng
}
};
this.searchComponent.setState({selectedLocality: locality}, true, () => {
this.searchComponent.selectLocality();
})
}
this.storesListComponent.once(StoresListComponentEvents.STORES_CHANGED, ({stores}) => {
this.chatbotComponent.emit(ChatbotComponentEvents.NEARBY_STORES_RETRIEVED, ({stores, locality}))
});
});
});
this.chatbotComponent.on(ChatbotComponentEvents.FILTER_STORES, (filters) => {
this.filterComponent.setActiveFilters(filters)
})
this.chatbotComponent.on(ChatbotComponentEvents.GET_DIRECTIONS, ({origin, destination}) => {
let directionState = {};
directionState = {...directionState, origin};
directionState = {...directionState, destination};
this.directionsComponent.setState(directionState, true, () => {
this.directionsComponent.emit(DirectionsComponentEvents.DESTINATION_CHANGED)
this.setDirectionsView();
});
})

this.searchComponent.on(SearchComponentEvents.SEARCH_CLEAR, () => {
this.urlParameterManager.setLocality(undefined)
this.storesListComponent.setState({nearbyLocation: undefined, stores: []});
Expand Down Expand Up @@ -304,7 +350,7 @@ export default class StoreLocator extends Component<IStoreLocator> {
}
}

setUserPosition(position: woosmap.map.LatLngLiteral | undefined): void {
setUserPosition(position: woosmap.map.LatLng | woosmap.map.LatLngLiteral | undefined): void {
if (!position && this.userLocationMarker) {
this.userLocationMarker.setMap(null);
return;
Expand Down Expand Up @@ -381,6 +427,7 @@ export default class StoreLocator extends Component<IStoreLocator> {
</div>
<div id="${getConfig().selectors.directionsContainerID}"></div>
<div id="${getConfig().selectors.roadbookContainerID}"></div>
</div>`;
</div>
<div id="${getConfig().selectors.chatContainerID}"></div>`;
}
}
1 change: 1 addition & 0 deletions src/assets/ai-bot.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading