Skip to content

Commit

Permalink
feat(confirm-route-leave): enhance confirmation modal functionality a…
Browse files Browse the repository at this point in the history
…nd naming

Signed-off-by: Wanjin Noh <[email protected]>
  • Loading branch information
WANZARGEN committed Nov 30, 2024
1 parent bfc5fc1 commit bf29c50
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
29 changes: 19 additions & 10 deletions apps/web/src/common/composables/confirm-route-leave/index.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,39 @@
import type { Ref } from 'vue';
import {
ref, readonly,
} from 'vue';
import type { Route } from 'vue-router';
import { useRouter } from 'vue-router/composables';

export const useConfirmRouteLeave = () => {
export const useConfirmRouteLeave = ({
passConfirmation,
}: {
passConfirmation?: Ref<boolean>
} = {}) => {
const router = useRouter();

const isConfirmBackModalVisible = ref(false);
const isConfirmLeaveModalVisible = ref(false);
const isConfirmed = ref(false);
let nextRoute: Route|undefined;

const openConfirmBackModal = () => {
isConfirmBackModalVisible.value = true;
isConfirmLeaveModalVisible.value = true;
};
const handleConfirmBack = () => {
const confirmRouteLeave = () => {
isConfirmed.value = true;
isConfirmBackModalVisible.value = false;
isConfirmLeaveModalVisible.value = false;
router.push(nextRoute);
};
const handleCancelBack = () => {
isConfirmBackModalVisible.value = false;
const stopRouteLeave = () => {
isConfirmLeaveModalVisible.value = false;
nextRoute = undefined;
};

const handleBeforeRouteLeave = (to, from, next) => {
if (passConfirmation?.value) {
next();
return;
}
if (!isConfirmed.value) {
nextRoute = to;
openConfirmBackModal();
Expand All @@ -35,9 +44,9 @@ export const useConfirmRouteLeave = () => {
};

return {
isConfirmBackModalVisible: readonly(isConfirmBackModalVisible),
handleConfirmBack,
handleCancelBack,
isConfirmLeaveModalVisible: readonly(isConfirmLeaveModalVisible),
confirmRouteLeave,
stopRouteLeave,
handleBeforeRouteLeave,
};
};
1 change: 1 addition & 0 deletions apps/web/src/common/composables/go-back/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ export const useGoBack = (mainRoute: Location) => {
return {
setPathFrom,
handleClickBackButton,
goBack: handleClickBackButton,
};
};

0 comments on commit bf29c50

Please sign in to comment.