-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add confirm-route-leave composable (#5121)
* refactor(go-back): use vue-router's useRouter for navigation Signed-off-by: Wanjin Noh <[email protected]> * feat(confirm-back-modal): add close and cancel events to ConfirmBackModal and DeleteModal Signed-off-by: Wanjin Noh <[email protected]> * feat: add confirm route leave composable for navigation confirmation Signed-off-by: Wanjin Noh <[email protected]> * feat(confirm-route-leave): enhance confirmation modal functionality and naming Signed-off-by: Wanjin Noh <[email protected]> * feat(field-group): add no-spacing prop to PFieldGroup component Signed-off-by: Wanjin Noh <[email protected]> * feat: add loading spinner component for navigation module Signed-off-by: Wanjin Noh <[email protected]> * feat(field-group): remove no-spacing class and adjust spacing styles Signed-off-by: Wanjin Noh <[email protected]> * feat(badge): add new subtle styles for peacock, coral, and red colors Signed-off-by: Wanjin Noh <[email protected]> * feat(go-back): replace useRouter with SpaceRouter for navigation handling Signed-off-by: Wanjin Noh <[email protected]> * feat: update route handling to use SpaceRouter instead of useRouter Signed-off-by: Wanjin Noh <[email protected]> --------- Signed-off-by: Wanjin Noh <[email protected]>
- Loading branch information
Showing
11 changed files
with
169 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
apps/web/src/common/composables/confirm-route-leave/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import type { Ref } from 'vue'; | ||
import { | ||
ref, readonly, | ||
} from 'vue'; | ||
import type { Location } from 'vue-router'; | ||
|
||
// CAUTION: Do not change to useRouter() because useRouter is only available in script setup | ||
import { SpaceRouter } from '@/router'; | ||
|
||
export const useConfirmRouteLeave = ({ | ||
passConfirmation, | ||
}: { | ||
passConfirmation?: Ref<boolean> | ||
} = {}) => { | ||
const isConfirmLeaveModalVisible = ref(false); | ||
const isConfirmed = ref(false); | ||
let nextRoute: Location|undefined; | ||
|
||
const openConfirmBackModal = () => { | ||
isConfirmLeaveModalVisible.value = true; | ||
}; | ||
const confirmRouteLeave = () => { | ||
isConfirmed.value = true; | ||
isConfirmLeaveModalVisible.value = false; | ||
if (nextRoute) SpaceRouter.router.push(nextRoute); | ||
}; | ||
const stopRouteLeave = () => { | ||
isConfirmLeaveModalVisible.value = false; | ||
nextRoute = undefined; | ||
}; | ||
|
||
const handleBeforeRouteLeave = (to, from, next) => { | ||
if (passConfirmation?.value) { | ||
next(); | ||
return; | ||
} | ||
if (!isConfirmed.value) { | ||
nextRoute = to; | ||
openConfirmBackModal(); | ||
next(false); | ||
} else { | ||
next(); | ||
} | ||
}; | ||
|
||
return { | ||
isConfirmLeaveModalVisible: readonly(isConfirmLeaveModalVisible), | ||
confirmRouteLeave, | ||
stopRouteLeave, | ||
handleBeforeRouteLeave, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
apps/web/src/common/modules/navigations/new-lsb/LSBLoadingSpinner.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<script setup lang="ts"> | ||
import { | ||
PSpinner, | ||
} from '@cloudforet/mirinae'; | ||
const props = defineProps<{ | ||
loading: boolean; | ||
}>(); | ||
</script> | ||
|
||
<template> | ||
<div class="relative"> | ||
<div v-show="props.loading" | ||
class="absolute flex flex-col px-4 w-full" | ||
> | ||
<p-spinner size="md" /> | ||
</div> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters