|
| 1 | +<script setup lang="ts"> |
| 2 | +import type { FeedbackRating, RatingTag, TagOption } from '../composables/useGlobalFeedback' |
| 3 | +import { RATING_TAGS } from '../composables/useGlobalFeedback' |
| 4 | +import { computed, ref, watch } from 'vue' |
| 5 | +
|
| 6 | +interface Props { |
| 7 | + modelValue: boolean |
| 8 | + selectedLevel: FeedbackRating | null |
| 9 | + selectedTags: RatingTag[] |
| 10 | + isSubmitting: boolean |
| 11 | +} |
| 12 | +
|
| 13 | +interface Emits { |
| 14 | + 'update:modelValue': [value: boolean] |
| 15 | + 'update:selectedTags': [tags: RatingTag[]] |
| 16 | + submit: [] |
| 17 | + tellUsMore: [] |
| 18 | +} |
| 19 | +
|
| 20 | +const props = defineProps<Props>() |
| 21 | +const emit = defineEmits<Emits>() |
| 22 | +
|
| 23 | +const submitted = ref(false) |
| 24 | +
|
| 25 | +watch( |
| 26 | + () => props.modelValue, |
| 27 | + (open) => { |
| 28 | + if (open) submitted.value = false |
| 29 | + }, |
| 30 | +) |
| 31 | +
|
| 32 | +const availableTags = computed<TagOption[]>(() => { |
| 33 | + if (!props.selectedLevel) return [] |
| 34 | + return RATING_TAGS[props.selectedLevel] |
| 35 | +}) |
| 36 | +
|
| 37 | +const ratingLabel = computed(() => { |
| 38 | + if (props.selectedLevel === 3) return 'Good' |
| 39 | + if (props.selectedLevel === 2) return 'Acceptable' |
| 40 | + if (props.selectedLevel === 1) return 'Poor' |
| 41 | + return '' |
| 42 | +}) |
| 43 | +
|
| 44 | +const canSubmit = computed(() => props.selectedTags.length > 0) |
| 45 | +
|
| 46 | +const pendingAction = ref<'submit' | 'tellUsMore' | null>(null) |
| 47 | +
|
| 48 | +watch( |
| 49 | + () => props.isSubmitting, |
| 50 | + (val) => { if (!val) pendingAction.value = null }, |
| 51 | +) |
| 52 | +
|
| 53 | +function onTellUsMore() { |
| 54 | + submitted.value = true |
| 55 | + pendingAction.value = 'tellUsMore' |
| 56 | + emit('tellUsMore') |
| 57 | +} |
| 58 | +
|
| 59 | +function onSubmit() { |
| 60 | + submitted.value = true |
| 61 | + pendingAction.value = 'submit' |
| 62 | + emit('submit') |
| 63 | +} |
| 64 | +
|
| 65 | +function toggleTag(tag: RatingTag) { |
| 66 | + const current = [...props.selectedTags] |
| 67 | + const idx = current.indexOf(tag) |
| 68 | + if (idx >= 0) { |
| 69 | + current.splice(idx, 1) |
| 70 | + } else { |
| 71 | + current.push(tag) |
| 72 | + } |
| 73 | + emit('update:selectedTags', current) |
| 74 | +} |
| 75 | +</script> |
| 76 | + |
| 77 | +<template> |
| 78 | + <v-dialog |
| 79 | + :model-value="modelValue" |
| 80 | + @update:model-value="emit('update:modelValue', $event)" |
| 81 | + max-width="450" |
| 82 | + > |
| 83 | + <v-card> |
| 84 | + <v-card-title class="text-h5">What did you notice?</v-card-title> |
| 85 | + <v-card-subtitle class="text-body2 px-6 pb-2 text-wrap"> |
| 86 | + You rated this area as <strong>{{ ratingLabel }}</strong |
| 87 | + >. What best describes what you observed? |
| 88 | + </v-card-subtitle> |
| 89 | + |
| 90 | + <v-card-text> |
| 91 | + <p v-if="submitted && !canSubmit" class="text-error text-caption mb-3 mt-0"> |
| 92 | + Please select at least one option. |
| 93 | + </p> |
| 94 | + <v-checkbox |
| 95 | + v-for="tag in availableTags" |
| 96 | + :key="tag.value" |
| 97 | + :model-value="selectedTags.includes(tag.value)" |
| 98 | + :label="tag.label" |
| 99 | + color="teal" |
| 100 | + density="compact" |
| 101 | + hide-details |
| 102 | + @update:model-value="toggleTag(tag.value)" |
| 103 | + /> |
| 104 | + </v-card-text> |
| 105 | + |
| 106 | + <v-card-actions> |
| 107 | + <v-spacer></v-spacer> |
| 108 | + <v-btn variant="text" @click="emit('update:modelValue', false)">Cancel</v-btn> |
| 109 | + <v-btn |
| 110 | + color="teal" |
| 111 | + variant="flat" |
| 112 | + :loading="isSubmitting && pendingAction === 'tellUsMore'" |
| 113 | + @click="onTellUsMore" |
| 114 | + > |
| 115 | + Tell Us More |
| 116 | + </v-btn> |
| 117 | + <v-btn |
| 118 | + color="teal" |
| 119 | + variant="flat" |
| 120 | + :loading="isSubmitting && pendingAction === 'submit'" |
| 121 | + @click="onSubmit" |
| 122 | + > |
| 123 | + Submit |
| 124 | + </v-btn> |
| 125 | + </v-card-actions> |
| 126 | + </v-card> |
| 127 | + </v-dialog> |
| 128 | +</template> |
0 commit comments