tipsEnabled set

This commit is contained in:
2026-06-29 20:05:42 +03:30
parent f4d5109b12
commit c02ff06e2c
+53 -9
View File
@@ -6,10 +6,6 @@
@close="dismissReview" @close="dismissReview"
> >
<div class="space-y-6"> <div class="space-y-6">
<p class="text-center text-sm text-muted">
خدمت: {{ activeReview?.serviceTitle ?? '—' }}
</p>
<StarRating v-model="rating" /> <StarRating v-model="rating" />
<template v-if="activeReview?.tipsEnabled"> <template v-if="activeReview?.tipsEnabled">
@@ -64,12 +60,10 @@
@close="closeTipModal" @close="closeTipModal"
> >
<form class="space-y-4" @submit.prevent="submitTip"> <form class="space-y-4" @submit.prevent="submitTip">
<AppInput <PriceInput
id="tipAmount" id="tipAmount"
v-model="tipAmountInput" v-model="tipAmountInput"
label="مبلغ (تومان)" label="مبلغ (تومان)"
inputmode="numeric"
ltr
placeholder="مثلاً ۵۰٬۰۰۰" placeholder="مثلاً ۵۰٬۰۰۰"
required required
/> />
@@ -79,10 +73,26 @@
</AppButton> </AppButton>
</form> </form>
</AppModal> </AppModal>
<AppModal
:open="tipSuccessOpen"
title="پرداخت موفق"
@close="closeTipSuccess"
>
<div class="space-y-4 text-center">
<p class="text-sm leading-7 text-muted">
پرداخت شما با موفقیت انجام شد.
</p>
<AppButton class="w-full" @click="closeTipSuccess">
باشه
</AppButton>
</div>
</AppModal>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { computed, onMounted, ref, watch } from 'vue'; import { computed, onMounted, ref, watch } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import { import {
fetchPendingReviews, fetchPendingReviews,
initiateBookingTip, initiateBookingTip,
@@ -92,17 +102,20 @@ import {
import { ApiError } from '@/api/client'; import { ApiError } from '@/api/client';
import StarRating from '@/components/booking/StarRating.vue'; import StarRating from '@/components/booking/StarRating.vue';
import AppButton from '@/components/ui/AppButton.vue'; import AppButton from '@/components/ui/AppButton.vue';
import AppInput from '@/components/ui/AppInput.vue';
import AppModal from '@/components/ui/AppModal.vue'; import AppModal from '@/components/ui/AppModal.vue';
import PriceInput from '@/components/ui/PriceInput.vue';
import { useAuthStore } from '@/stores/auth'; import { useAuthStore } from '@/stores/auth';
import { parsePriceInput } from '@/utils/format'; import { parsePriceInput } from '@/utils/format';
const auth = useAuthStore(); const auth = useAuthStore();
const route = useRoute();
const router = useRouter();
const pending = ref<PendingBookingReview[]>([]); const pending = ref<PendingBookingReview[]>([]);
const activeReview = ref<PendingBookingReview | null>(null); const activeReview = ref<PendingBookingReview | null>(null);
const reviewOpen = ref(false); const reviewOpen = ref(false);
const tipOpen = ref(false); const tipOpen = ref(false);
const tipSuccessOpen = ref(false);
const rating = ref(0); const rating = ref(0);
const error = ref(''); const error = ref('');
const submitting = ref(false); const submitting = ref(false);
@@ -157,6 +170,29 @@ function closeTipModal() {
tipError.value = ''; tipError.value = '';
} }
function showTipSuccess() {
tipSuccessOpen.value = true;
}
function closeTipSuccess() {
tipSuccessOpen.value = false;
}
function handleTipQuery() {
const raw = route.query.tip;
if (raw !== 'success' && raw !== 'failed') return;
if (raw === 'success') {
showTipSuccess();
} else {
tipError.value = 'پرداخت ناموفق بود.';
}
const nextQuery = { ...route.query };
delete nextQuery.tip;
void router.replace({ query: nextQuery });
}
async function submitWithoutTip() { async function submitWithoutTip() {
if (!activeReview.value || !rating.value) return; if (!activeReview.value || !rating.value) return;
submitting.value = true; submitting.value = true;
@@ -193,7 +229,7 @@ async function submitTip() {
pending.value = pending.value.filter((item) => item.bookingId !== bookingId); pending.value = pending.value.filter((item) => item.bookingId !== bookingId);
activeReview.value = pending.value[0] ?? null; activeReview.value = pending.value[0] ?? null;
if (result.mock) { if (result.mock) {
if (activeReview.value) reviewOpen.value = true; showTipSuccess();
return; return;
} }
window.location.href = result.startUrl; window.location.href = result.startUrl;
@@ -212,6 +248,14 @@ watch(
); );
onMounted(() => { onMounted(() => {
handleTipQuery();
void loadPending(); void loadPending();
}); });
watch(
() => route.query.tip,
() => {
handleTipQuery();
},
);
</script> </script>