-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
120 additions
and
2 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
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,62 @@ | ||
<script setup lang="ts"> | ||
import type { RequestStatus } from '/@/features/requestStatus/model' | ||
import { onMounted, onUnmounted, ref } from 'vue' | ||
import { useModal } from '/@/components/modal/composables/useModal' | ||
import ModalWrapper from '/@/components/modal/ModalWrapper.vue' | ||
import StatusChangeModal from '/@/components/modal/StatusChangeModal.vue' | ||
defineProps<{ | ||
options: { key: string; value: RequestStatus }[] | ||
currentValue: RequestStatus | ||
}>() | ||
const emit = defineEmits<{ | ||
(e: 'closeMenu'): void | ||
}>() | ||
const handleSelectOption = (status: RequestStatus) => { | ||
// TODO: emitして一般化 | ||
nextStatus.value = status | ||
openModal() | ||
} | ||
const containerRef = ref<HTMLDivElement | null>(null) | ||
const nextStatus = ref<RequestStatus>() | ||
const { shouldShowModal, openModal, closeModal } = useModal() | ||
const callback = () => { | ||
emit('closeMenu') | ||
} | ||
onMounted(() => { | ||
window.addEventListener('click', callback) | ||
}) | ||
onUnmounted(() => { | ||
window.removeEventListener('click', callback) | ||
}) | ||
</script> | ||
|
||
<template> | ||
<div | ||
ref="containerRef" | ||
class="bg-white rounded-md p-2 flex flex-col gap-2 border" | ||
@click.stop=""> | ||
<div | ||
v-for="option in options" | ||
:key="option.value" | ||
class="hover:bg-gray-200 rounded p-1"> | ||
<button | ||
class="w-full h-full text-left" | ||
@click="handleSelectOption(option.value)"> | ||
{{ option.key }} | ||
</button> | ||
</div> | ||
<ModalWrapper v-if="shouldShowModal" @close-modal="closeModal"> | ||
<StatusChangeModal | ||
v-if="nextStatus" | ||
:next-status="nextStatus" | ||
@close-modal="closeModal" /> | ||
</ModalWrapper> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import type { RequestStatus } from '/@/features/requestStatus/model' | ||
|
||
import { storeToRefs } from 'pinia' | ||
import { useRequestDetailStore } from '/@/stores/requestDetail' | ||
import { useUserStore } from '/@/stores/user' | ||
import type { RequestDetail } from '/@/features/request/model' | ||
import { computed } from 'vue' | ||
|
||
export const useStatusOptions = (request: RequestDetail) => { | ||
const userStore = useUserStore() | ||
const requestDetailStore = useRequestDetailStore() | ||
const { isRequestCreator } = requestDetailStore | ||
|
||
const { me, isAdmin } = storeToRefs(userStore) | ||
const hasAuthority = isRequestCreator(me.value) | ||
|
||
const showToSubmitted = | ||
(hasAuthority && request.status === 'fix_required') || | ||
(isAdmin.value && | ||
(request.status === 'fix_required' || request.status === 'accepted')) | ||
const showToRequired = isAdmin.value && request.status === 'submitted' | ||
const showToAccepted = isAdmin.value && request.status === 'submitted' | ||
const showToRejected = isAdmin.value && request.status === 'submitted' | ||
|
||
const statusOptions = computed< | ||
{ value: RequestStatus; key: string; show: boolean }[] | ||
>(() => [ | ||
{ value: 'submitted', key: '承認待ちにする', show: showToSubmitted }, //TODO: 表示するべきか確認 | ||
{ value: 'rejected', key: '却下する', show: showToRejected }, | ||
{ value: 'fix_required', key: '要修正にする', show: showToRequired }, | ||
{ value: 'accepted', key: '承認する', show: showToAccepted } | ||
]) | ||
const showStatusOptions = computed(() => | ||
statusOptions.value | ||
.filter(option => option.show) | ||
.map(option => ({ value: option.value, key: option.key })) | ||
) | ||
|
||
return { statusOptions: showStatusOptions.value } | ||
} |