@roomstay/frontend 2.6.11 → 2.6.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -37,7 +37,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
38
|
exports.renderRecentSearchesEngineElement = exports.RecentSearchesEngineElement = void 0;
|
|
39
39
|
const contexts_1 = require("../../contexts/index.js");
|
|
40
|
-
const hooks_1 = require("../../hooks/index.js");
|
|
41
40
|
const dayjs_1 = __importDefault(require("dayjs"));
|
|
42
41
|
const react_1 = __importStar(require("react"));
|
|
43
42
|
const react_dom_1 = require("react-dom");
|
|
@@ -46,19 +45,33 @@ const BEButton_1 = __importDefault(require("../../components/generic/BEButton"))
|
|
|
46
45
|
const Icon_1 = require("../../components/generic/Icon/Icon");
|
|
47
46
|
const RecentSearchesCard_1 = __importDefault(require("../../components/generic/RecentSearchesCard"));
|
|
48
47
|
const Text_1 = __importStar(require("../../components/generic/Text"));
|
|
48
|
+
const RoomstayThemeEngine_1 = __importDefault(require("../../providers/RoomstayThemeEngine"));
|
|
49
49
|
const SessionProvider_1 = __importDefault(require("../../providers/SessionProvider"));
|
|
50
50
|
const Translation_1 = require("../../translations/Translation");
|
|
51
51
|
const Color_1 = require("../../util/Color");
|
|
52
52
|
const GetStepRoom_1 = __importDefault(require("../../util/GetStepRoom"));
|
|
53
53
|
const ScreenSize_1 = __importDefault(require("../../util/ScreenSize"));
|
|
54
54
|
const RecentSearchesEngineElement = ({ engine }) => {
|
|
55
|
-
const { hotel } = (0, hooks_1.useCurrentHotel)();
|
|
56
55
|
const { t } = (0, react_i18next_1.useTranslation)();
|
|
57
56
|
const [currentSessions, setCurrentSessions] = (0, react_1.useState)([]);
|
|
58
57
|
const beContext = (0, react_1.useContext)(contexts_1.BookingEngineContext);
|
|
58
|
+
const hotel = (0, react_1.useMemo)(() => {
|
|
59
|
+
var _a;
|
|
60
|
+
const config = engine.getConfig();
|
|
61
|
+
const selectedHotel = (_a = config === null || config === void 0 ? void 0 : config.company) === null || _a === void 0 ? void 0 : _a.selectedHotel;
|
|
62
|
+
if (selectedHotel) {
|
|
63
|
+
return config.company.hotels.find((hotel) => hotel.hotelID === selectedHotel || hotel.hotelID === (selectedHotel === null || selectedHotel === void 0 ? void 0 : selectedHotel.hotelID));
|
|
64
|
+
}
|
|
65
|
+
}, [engine]);
|
|
59
66
|
(0, react_1.useEffect)(() => {
|
|
60
67
|
resetSessions();
|
|
61
68
|
}, []);
|
|
69
|
+
(0, react_1.useEffect)(() => {
|
|
70
|
+
if (hotel) {
|
|
71
|
+
console.log(hotel);
|
|
72
|
+
RoomstayThemeEngine_1.default.changeTheme(hotel === null || hotel === void 0 ? void 0 : hotel.colors);
|
|
73
|
+
}
|
|
74
|
+
}, [hotel]);
|
|
62
75
|
const resetSessions = () => {
|
|
63
76
|
engine
|
|
64
77
|
.getSessionProvider()
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RecentSearchesEngineElement.js","sourceRoot":"/","sources":["src/engines/RecentSearchesEngine/RecentSearchesEngineElement.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAAuF;AACvF,2CAAkD;AAClD,kDAA0B;AAC1B,+CAA+D;AAC/D,yCAAmC;AACnC,iDAA+C;AAE/C,6EAAqD;AACrD,yDAA0D;AAC1D,iGAAyE;AACzE,kEAA2D;AAI3D,kFAA0D;AAC1D,4DAAyD;AACzD,wCAAqC;AACrC,qEAA6C;AAC7C,mEAA2C;AAMpC,MAAM,2BAA2B,GAAG,CAAC,EAAE,MAAM,EAAoC,EAAE,EAAE;IACxF,MAAM,EAAE,KAAK,EAAE,GAAG,IAAA,uBAAe,GAAE,CAAC;IACpC,MAAM,EAAE,CAAC,EAAE,GAAG,IAAA,8BAAc,GAAE,CAAC;IAE/B,MAAM,CAAC,eAAe,EAAE,k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YAAY,CAAC,WAAW,EAAE;wBACrC,SAAS,EAAE,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,IAAI;qBACzB,CAAC,CACK,CACT,CACJ,CACJ,CACJ,CACT,CAAC,CAAC,CAAC,CACA,6DAAK,CACR,CAAC;AACN,CAAC,CAAC;AAvHW,QAAA,2BAA2B,+BAuHtC;AAEK,MAAM,iCAAiC,GAAG,CAAC,SAAkB,EAAE,MAA4B,EAAE,EAAE;IAClG,IAAA,kBAAM,EACF,8BAAC,sCAA2B,IAAC,MAAM,EAAE,MAAM;QACvC,8BAAC,mCAA2B,IAAC,MAAM,EAAE,MAAM,GAAI,CACrB,EAC9B,SAAS,CACZ,CAAC;AACN,CAAC,CAAC;AAPW,QAAA,iCAAiC,qCAO5C","sourcesContent":["import { BookingEngineContext, BookingEngineContextWrapper } from '@frontend/contexts';\nimport { useCurrentHotel } from '@frontend/hooks';\nimport dayjs from 'dayjs';\nimport React, { useContext, useEffect, useState } from 'react';\nimport { render } from 'react-dom';\nimport { useTranslation } from 'react-i18next';\n\nimport BEButton from '@/components/generic/BEButton';\nimport { IconType } from '@/components/generic/Icon/Icon';\nimport RecentSearchesCard from '@/components/generic/RecentSearchesCard';\nimport Text, { TextType } from '@/components/generic/Text';\nimport type { RecentSearchesEngine } from '@/engines/RecentSearchesEngine/RecentSearchesEngine';\nimport BasketRow from '@/models/BasketRow';\nimport { RoomstaySession } from '@/models/RoomstaySession';\nimport SessionProvider from '@/providers/SessionProvider';\nimport { Translation } from '@/translations/Translation';\nimport { Color } from '@/util/Color';\nimport getStepRoom from '@/util/GetStepRoom';\nimport ScreenSize from '@/util/ScreenSize';\n\nexport interface RecentSearchesEngineElementProps {\n engine: RecentSearchesEngine;\n}\n\nexport const RecentSearchesEngineElement = ({ engine }: RecentSearchesEngineElementProps) => {\n const { hotel } = useCurrentHotel();\n const { t } = useTranslation();\n\n const [currentSessions, setCurrentSessions] = useState<RoomstaySession[]>([]);\n\n const beContext = useContext(BookingEngineContext);\n\n useEffect(() => {\n resetSessions();\n }, []);\n\n const resetSessions = () => {\n engine\n .getSessionProvider()\n .getAllSessions()\n .then((sessions) => {\n const sessionsToUse: RoomstaySession[] = [];\n\n sessions.forEach((session) => {\n if (!hotel || (hotel?.hotelID === session.hotelID && session.basketRows?.length > 0)) {\n let hasValidRow = false;\n session.basketRows.forEach((basket) => {\n if (basket.isValid() && basket.getStartDate().isAfter(dayjs())) {\n hasValidRow = true;\n }\n });\n\n if (hasValidRow) {\n sessionsToUse.push(session);\n }\n }\n });\n\n sessionsToUse.reverse();\n\n setCurrentSessions(sessionsToUse);\n });\n };\n\n const smallBlurb = (\n <Text color={Color.White} type={TextType.Small}>\n {t(Translation.RecentSearch.SubTagLine)}\n </Text>\n );\n\n const onRemoveCard = async (session: RoomstaySession) => {\n const provider = new SessionProvider();\n await provider.initialize(session.id);\n\n provider.deleteSession();\n\n resetSessions();\n };\n\n const redirectToCheckout = () => {\n window.open(hotel?.checkoutUrl);\n };\n\n return currentSessions.length ? (\n <div style={{ backgroundColor: Color.Navy }}>\n <div className=\"container\">\n <div className=\"u-pad-top-bottom--heavy\">\n <div className=\"u-marg-bottom\">\n <Text color={Color.White} bold>\n {t(Translation.RecentSearch.RecentSearches)}\n </Text>\n {beContext.screenSize <= ScreenSize.Medium && smallBlurb}\n </div>\n <div className=\"row u-marg-bottom\">\n {!!currentSessions?.length &&\n currentSessions.slice(0, 2).map((session: RoomstaySession) => {\n let validRow: BasketRow | undefined = undefined;\n\n for (const row of session.basketRows) {\n if (row.isValid()) {\n validRow = row;\n break;\n }\n }\n\n const removeCard = () => {\n onRemoveCard(session);\n };\n\n const onViewRates = async () => {\n const manager = new SessionProvider();\n await manager.initialize(session.id);\n\n manager\n .updateSession({\n step: getStepRoom().getName(),\n })\n .then(() => {\n window.open(`${hotel?.checkoutUrl ?? '/checkout/'}#${getStepRoom().getStepUrl()}?session=${session.id}`, '_self');\n });\n };\n\n return (\n <div key={validRow?.getID()} className=\"col-lg-6\">\n <RecentSearchesCard basketRow={validRow as BasketRow} onRemove={removeCard} onViewRatesClicked={onViewRates} />\n </div>\n );\n })}\n </div>\n <div className=\"u-flex u-flex-align-center flex-column flex-md-row justify-align-content-md-center\">\n {beContext.screenSize > ScreenSize.Medium && smallBlurb}\n <BEButton icon={IconType.ArrowRight} iconPosition=\"right\" primary filled onClick={redirectToCheckout}>\n {t(Translation.RecentSearch.SeeAllRooms, {\n hotelName: hotel?.name,\n })}\n </BEButton>\n </div>\n </div>\n </div>\n </div>\n ) : (\n <></>\n );\n};\n\nexport const renderRecentSearchesEngineElement = (container: Element, engine: RecentSearchesEngine) => {\n render(\n <BookingEngineContextWrapper engine={engine}>\n <RecentSearchesEngineElement engine={engine} />\n </BookingEngineContextWrapper>,\n container\n );\n};\n"]}
|
|
1
|
+
{"version":3,"file":"RecentSearchesEngineElement.js","sourceRoot":"/","sources":["src/engines/RecentSearchesEngine/RecentSearchesEngineElement.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAAuF;AAEvF,kDAA0B;AAC1B,+CAAwE;AACxE,yCAAmC;AACnC,iDAA+C;AAE/C,6EAAqD;AACrD,yDAA0D;AAC1D,iGAAyE;AACzE,kEAA2D;AAK3D,0FAAkE;AAClE,kFAA0D;AAC1D,4DAAyD;AACzD,wCAAqC;AACrC,qEAA6C;AAC7C,mEAA2C;AAMpC,MAAM,2BAA2B,GAAG,CAAC,EAAE,MAAM,EAAoC,EAAE,EAAE;IACxF,MAAM,EAAE,CAAC,EAAE,GAAG,IAAA,8BAAc,GAAE,CAAC;IAE/B,MAAM,CAAC,eAAe,EAAE,kBAAkB,CAAC,GAAG,IAAA,gBAAQ,EAAoB,EAAE,CAAC,CAAC;IAE9E,MAAM,SAAS,GAAG,IAAA,kBAAU,EAAC,+BAAoB,CAAC,CAAC;IACnD,MAAM,KAAK,GAAG,IAAA,eAAO,EAAC,GAAG,EAAE;;QACvB,MAAM,MAAM,GAAG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CAAA,CAAC;wBAEF,OAAO,CACH,uCAAK,GAAG,EAAE,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,KAAK,EAAE,EAAE,SAAS,EAAC,UAAU;4BAC7C,8BAAC,4BAAkB,IAAC,SAAS,EAAE,QAAqB,EAAE,QAAQ,EAAE,UAAU,EAAE,kBAAkB,EAAE,WAAW,GAAI,CAC7G,CACT,CAAC;oBACN,CAAC,CAAC,CACJ;gBACN,uCAAK,SAAS,EAAC,oFAAoF;oBAC9F,SAAS,CAAC,UAAU,GAAG,oBAAU,CAAC,MAAM,IAAI,UAAU;oBACvD,8BAAC,kBAAQ,IAAC,IAAI,EAAE,eAAQ,CAAC,UAAU,EAAE,YAAY,EAAC,OAAO,EAAC,OAAO,QAAC,MAAM,QAAC,OAAO,EAAE,kBAAkB,IAC/F,CAAC,CAAC,yBAAW,CAAC,YAAY,CAAC,WAAW,EAAE;wBACrC,SAAS,EAAE,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,IAAI;qBACzB,CAAC,CACK,CACT,CACJ,CACJ,CACJ,CACT,CAAC,CAAC,CAAC,CACA,6DAAK,CACR,CAAC;AACN,CAAC,CAAC;AArIW,QAAA,2BAA2B,+BAqItC;AAEK,MAAM,iCAAiC,GAAG,CAAC,SAAkB,EAAE,MAA4B,EAAE,EAAE;IAClG,IAAA,kBAAM,EACF,8BAAC,sCAA2B,IAAC,MAAM,EAAE,MAAM;QACvC,8BAAC,mCAA2B,IAAC,MAAM,EAAE,MAAM,GAAI,CACrB,EAC9B,SAAS,CACZ,CAAC;AACN,CAAC,CAAC;AAPW,QAAA,iCAAiC,qCAO5C","sourcesContent":["import { BookingEngineContext, BookingEngineContextWrapper } from '@frontend/contexts';\nimport { useCurrentHotel } from '@frontend/hooks';\nimport dayjs from 'dayjs';\nimport React, { useContext, useEffect, useMemo, useState } from 'react';\nimport { render } from 'react-dom';\nimport { useTranslation } from 'react-i18next';\n\nimport BEButton from '@/components/generic/BEButton';\nimport { IconType } from '@/components/generic/Icon/Icon';\nimport RecentSearchesCard from '@/components/generic/RecentSearchesCard';\nimport Text, { TextType } from '@/components/generic/Text';\nimport type { RecentSearchesEngine } from '@/engines/RecentSearchesEngine/RecentSearchesEngine';\nimport BasketRow from '@/models/BasketRow';\nimport { ConfigHotel } from '@/models/Client/Hotel/Hotel';\nimport { RoomstaySession } from '@/models/RoomstaySession';\nimport RoomstayThemeEngine from '@/providers/RoomstayThemeEngine';\nimport SessionProvider from '@/providers/SessionProvider';\nimport { Translation } from '@/translations/Translation';\nimport { Color } from '@/util/Color';\nimport getStepRoom from '@/util/GetStepRoom';\nimport ScreenSize from '@/util/ScreenSize';\n\nexport interface RecentSearchesEngineElementProps {\n engine: RecentSearchesEngine;\n}\n\nexport const RecentSearchesEngineElement = ({ engine }: RecentSearchesEngineElementProps) => {\n const { t } = useTranslation();\n\n const [currentSessions, setCurrentSessions] = useState<RoomstaySession[]>([]);\n\n const beContext = useContext(BookingEngineContext);\n const hotel = useMemo(() => {\n const config = engine.getConfig();\n const selectedHotel = config?.company?.selectedHotel;\n\n if (selectedHotel) {\n return config.company.hotels.find((hotel) => hotel.hotelID === selectedHotel || hotel.hotelID === (selectedHotel as ConfigHotel)?.hotelID);\n }\n }, [engine]);\n\n useEffect(() => {\n resetSessions();\n }, []);\n\n useEffect(() => {\n if (hotel) {\n console.log(hotel);\n RoomstayThemeEngine.changeTheme(hotel?.colors);\n }\n }, [hotel]);\n\n const resetSessions = () => {\n engine\n .getSessionProvider()\n .getAllSessions()\n .then((sessions) => {\n const sessionsToUse: RoomstaySession[] = [];\n\n sessions.forEach((session) => {\n if (!hotel || (hotel?.hotelID === session.hotelID && session.basketRows?.length > 0)) {\n let hasValidRow = false;\n session.basketRows.forEach((basket) => {\n if (basket.isValid() && basket.getStartDate().isAfter(dayjs())) {\n hasValidRow = true;\n }\n });\n\n if (hasValidRow) {\n sessionsToUse.push(session);\n }\n }\n });\n\n sessionsToUse.reverse();\n\n setCurrentSessions(sessionsToUse);\n });\n };\n\n const smallBlurb = (\n <Text color={Color.White} type={TextType.Small}>\n {t(Translation.RecentSearch.SubTagLine)}\n </Text>\n );\n\n const onRemoveCard = async (session: RoomstaySession) => {\n const provider = new SessionProvider();\n await provider.initialize(session.id);\n\n provider.deleteSession();\n\n resetSessions();\n };\n\n const redirectToCheckout = () => {\n window.open(hotel?.checkoutUrl);\n };\n\n return currentSessions.length ? (\n <div style={{ backgroundColor: Color.Navy }}>\n <div className=\"container\">\n <div className=\"u-pad-top-bottom--heavy\">\n <div className=\"u-marg-bottom\">\n <Text color={Color.White} bold>\n {t(Translation.RecentSearch.RecentSearches)}\n </Text>\n {beContext.screenSize <= ScreenSize.Medium && smallBlurb}\n </div>\n <div className=\"row u-marg-bottom\">\n {!!currentSessions?.length &&\n currentSessions.slice(0, 2).map((session: RoomstaySession) => {\n let validRow: BasketRow | undefined = undefined;\n\n for (const row of session.basketRows) {\n if (row.isValid()) {\n validRow = row;\n break;\n }\n }\n\n const removeCard = () => {\n onRemoveCard(session);\n };\n\n const onViewRates = async () => {\n const manager = new SessionProvider();\n await manager.initialize(session.id);\n\n manager\n .updateSession({\n step: getStepRoom().getName(),\n })\n .then(() => {\n window.open(`${hotel?.checkoutUrl ?? '/checkout/'}#${getStepRoom().getStepUrl()}?session=${session.id}`, '_self');\n });\n };\n\n return (\n <div key={validRow?.getID()} className=\"col-lg-6\">\n <RecentSearchesCard basketRow={validRow as BasketRow} onRemove={removeCard} onViewRatesClicked={onViewRates} />\n </div>\n );\n })}\n </div>\n <div className=\"u-flex u-flex-align-center flex-column flex-md-row justify-align-content-md-center\">\n {beContext.screenSize > ScreenSize.Medium && smallBlurb}\n <BEButton icon={IconType.ArrowRight} iconPosition=\"right\" primary filled onClick={redirectToCheckout}>\n {t(Translation.RecentSearch.SeeAllRooms, {\n hotelName: hotel?.name,\n })}\n </BEButton>\n </div>\n </div>\n </div>\n </div>\n ) : (\n <></>\n );\n};\n\nexport const renderRecentSearchesEngineElement = (container: Element, engine: RecentSearchesEngine) => {\n render(\n <BookingEngineContextWrapper engine={engine}>\n <RecentSearchesEngineElement engine={engine} />\n </BookingEngineContextWrapper>,\n container\n );\n};\n"]}
|