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

fix: browser back button not working #13345

Merged
merged 29 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
8b475bc
fixed the browser back button not woking
abhijeetsingh-22 Jan 20, 2024
f5e25c7
fix back button
abhijeetsingh-22 Jan 22, 2024
f55f2ab
Merge branch 'main' into fix_browser_back_button
abhijeetsingh-22 Jan 23, 2024
2d9ac01
Merge branch 'main' into fix_browser_back_button
PeerRich Jan 25, 2024
946d522
Merge branch 'main' into fix_browser_back_button
Udit-takkar Jan 29, 2024
9538077
Merge branch 'main' into fix_browser_back_button
keithwillcode Feb 8, 2024
178bc87
Merge branch 'main' into fix_browser_back_button
keithwillcode Feb 14, 2024
448060c
Merge branch 'main' into fix_browser_back_button
abhijeetsingh-22 Feb 15, 2024
19f1419
merge main
abhijeetsingh-22 Feb 17, 2024
a9bd4b3
added shouldReplace param to query-params helper.
abhijeetsingh-22 Feb 17, 2024
922b5e9
revert yarn.lock
abhijeetsingh-22 Feb 17, 2024
335dd27
Merge branch 'main' into fix_browser_back_button
abhijeetsingh-22 Feb 20, 2024
b99073d
Merge branch 'main' into fix_browser_back_button
abhijeetsingh-22 Feb 21, 2024
8e6229d
Merge branch 'main' into fix_browser_back_button
emrysal Feb 22, 2024
7eddcf7
Merge branch 'main' into fix_browser_back_button
keithwillcode Feb 22, 2024
1b4be9d
Merge branch 'main' into fix_browser_back_button
CarinaWolli Feb 22, 2024
bdc6e0a
Merge branch 'main' into fix_browser_back_button
CarinaWolli Feb 26, 2024
6de259a
Merge branch 'main' into fix_browser_back_button
keithwillcode Feb 28, 2024
51ed075
Merge branch 'main' into fix_browser_back_button
CarinaWolli Feb 28, 2024
3d45034
Merge branch 'main' into fix_browser_back_button
PeerRich Mar 2, 2024
6cc2b1d
Merge branch 'main' into fix_browser_back_button
PeerRich Mar 4, 2024
d870926
Merge branch 'main' into fix_browser_back_button
joeauyeung Mar 4, 2024
6cd0b4c
Merge branch 'main' into fix_browser_back_button
keithwillcode Apr 4, 2024
9f9d6ca
Merge branch 'main' into fix_browser_back_button
keithwillcode Apr 12, 2024
aaec6f6
Merge branch 'main' into fix_browser_back_button
Udit-takkar Apr 17, 2024
7fa800e
fix: test
Udit-takkar Apr 18, 2024
6d9636a
Merge branch 'main' into fix_browser_back_button
Udit-takkar Apr 18, 2024
07c9065
Merge branch 'main' into fix_browser_back_button
CarinaWolli Apr 19, 2024
5d358ae
Merge branch 'main' into fix_browser_back_button
joeauyeung Apr 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/features/bookings/Booker/Booker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ const BookerComponent = ({
return setBookerState("booking");
}, [event, selectedDate, selectedTimeslot, setBookerState]);

const slot = getQueryParam("slot");
useEffect(() => {
setSelectedTimeslot(slot || null);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sure that the selectedTimeslot updates in the store when it is changed in the query param. And it sets it to null when the slot query param is not present

}, [slot, setSelectedTimeslot]);
const EventBooker = useMemo(() => {
return bookerState === "booking" ? (
<BookEventForm
Expand Down
4 changes: 2 additions & 2 deletions packages/features/bookings/Booker/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ export const useBookerStore = create<BookerStore>((set, get) => ({
});
updateQueryParam("month", month);
updateQueryParam("date", selectedDate ?? "");
updateQueryParam("slot", selectedTimeslot ?? "");
updateQueryParam("slot", selectedTimeslot ?? "", false);
}
//removeQueryParam("layout");
},
Expand All @@ -332,7 +332,7 @@ export const useBookerStore = create<BookerStore>((set, get) => ({
selectedTimeslot: getQueryParam("slot") || null,
setSelectedTimeslot: (selectedTimeslot: string | null) => {
set({ selectedTimeslot });
updateQueryParam("slot", selectedTimeslot ?? "");
updateQueryParam("slot", selectedTimeslot ?? "", false);
},
formValues: {},
setFormValues: (formValues: Record<string, any>) => {
Expand Down
24 changes: 18 additions & 6 deletions packages/features/bookings/Booker/utils/query-param.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
export const updateQueryParam = (param: string, value: string | number) => {
export const updateQueryParam = (param: string, value: string | number, shouldReplace = true) => {
if (typeof window === "undefined") return;

const url = new URL(window.location.href);
if (url.searchParams.get(param) === value) return;

if (value === "" || value === "null") {
url.searchParams.delete(param);
removeQueryParam(param, shouldReplace);
return;
} else {
url.searchParams.set(param, `${value}`);
}

window.history.pushState({}, "", url.href);
if (shouldReplace) {
window.history.replaceState({ ...window.history.state, as: url.href }, "", url.href);
} else {
window.history.pushState({ ...window.history.state, as: url.href }, "", url.href);
}
};

export const getQueryParam = (param: string) => {
Expand All @@ -17,10 +23,16 @@ export const getQueryParam = (param: string) => {
return new URLSearchParams(window.location.search).get(param);
};

export const removeQueryParam = (param: string) => {
export const removeQueryParam = (param: string, shouldReplace = true) => {
if (typeof window === "undefined") return;

const url = new URL(window.location.href);
if (!url.searchParams.get(param)) return;

url.searchParams.delete(param);
window.history.pushState({}, "", url.href);
if (shouldReplace) {
window.history.replaceState({ ...window.history.state, as: url.href }, "", url.href);
} else {
window.history.pushState({ ...window.history.state, as: url.href }, "", url.href);
}
};
4 changes: 3 additions & 1 deletion packages/features/calendars/DatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,9 @@ const Days = ({
// If selected date not available in the month, select the first available date of the month
props.onChange(firstAvailableDateOfTheMonth);
}

if (isSelectedDateAvailable) {
props.onChange(dayjs(selected));
}
if (!firstAvailableDateOfTheMonth) {
props.onChange(null);
}
Expand Down