Fix toast dismiss, add delete confirms, and polish dashboard CTAs.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -2,11 +2,17 @@
|
|||||||
import { useToast } from '@/composables/useToast'
|
import { useToast } from '@/composables/useToast'
|
||||||
|
|
||||||
const { toasts, dismiss } = useToast()
|
const { toasts, dismiss } = useToast()
|
||||||
|
|
||||||
|
function onDismiss(id: string, event: MouseEvent) {
|
||||||
|
event.preventDefault()
|
||||||
|
event.stopPropagation()
|
||||||
|
dismiss(id)
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="toast-container" aria-live="polite" aria-relevant="additions">
|
<div class="toast-container" aria-live="polite" aria-relevant="additions">
|
||||||
<TransitionGroup name="toast">
|
<TransitionGroup name="toast" tag="div" class="toast-container__list">
|
||||||
<div
|
<div
|
||||||
v-for="toast in toasts"
|
v-for="toast in toasts"
|
||||||
:key="toast.id"
|
:key="toast.id"
|
||||||
@@ -15,7 +21,12 @@ const { toasts, dismiss } = useToast()
|
|||||||
role="status"
|
role="status"
|
||||||
>
|
>
|
||||||
<p class="toast__message">{{ toast.message }}</p>
|
<p class="toast__message">{{ toast.message }}</p>
|
||||||
<button type="button" class="toast__close" aria-label="بستن" @click="dismiss(toast.id)">
|
<button
|
||||||
|
type="button"
|
||||||
|
class="toast__close"
|
||||||
|
aria-label="بستن"
|
||||||
|
@click="onDismiss(toast.id, $event)"
|
||||||
|
>
|
||||||
×
|
×
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
@@ -28,11 +39,15 @@ const { toasts, dismiss } = useToast()
|
|||||||
position: fixed;
|
position: fixed;
|
||||||
top: calc(var(--header-height) + 12px);
|
top: calc(var(--header-height) + 12px);
|
||||||
left: 16px;
|
left: 16px;
|
||||||
z-index: 1100;
|
z-index: 1200;
|
||||||
|
width: min(360px, calc(100vw - 32px));
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toast-container__list {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
gap: 8px;
|
gap: 8px;
|
||||||
width: min(360px, calc(100vw - 32px));
|
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,18 +92,34 @@ const { toasts, dismiss } = useToast()
|
|||||||
}
|
}
|
||||||
|
|
||||||
.toast__close {
|
.toast__close {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
width: 28px;
|
||||||
|
height: 28px;
|
||||||
|
margin: -4px;
|
||||||
border: none;
|
border: none;
|
||||||
|
border-radius: 6px;
|
||||||
background: transparent;
|
background: transparent;
|
||||||
color: var(--color-text-muted);
|
color: var(--color-text-muted);
|
||||||
font-size: 1.125rem;
|
font-size: 1.25rem;
|
||||||
line-height: 1;
|
line-height: 1;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
|
cursor: pointer;
|
||||||
|
pointer-events: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toast__close:hover {
|
||||||
|
background: rgba(15, 23, 42, 0.06);
|
||||||
|
color: var(--color-text);
|
||||||
}
|
}
|
||||||
|
|
||||||
.toast-enter-active,
|
.toast-enter-active,
|
||||||
.toast-leave-active {
|
.toast-leave-active {
|
||||||
transition: opacity 0.18s ease, transform 0.18s ease;
|
transition:
|
||||||
|
opacity 0.18s ease,
|
||||||
|
transform 0.18s ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
.toast-enter-from,
|
.toast-enter-from,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { reactive } from 'vue'
|
import { reactive, toRef } from 'vue'
|
||||||
|
|
||||||
export type ToastTone = 'success' | 'error' | 'info' | 'warning'
|
export type ToastTone = 'success' | 'error' | 'info' | 'warning'
|
||||||
|
|
||||||
@@ -19,12 +19,15 @@ function push(message: string, tone: ToastTone) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function dismiss(id: string) {
|
function dismiss(id: string) {
|
||||||
state.items = state.items.filter((item) => item.id !== id)
|
const index = state.items.findIndex((item) => item.id === id)
|
||||||
|
if (index !== -1) {
|
||||||
|
state.items.splice(index, 1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useToast() {
|
export function useToast() {
|
||||||
return {
|
return {
|
||||||
toasts: state.items,
|
toasts: toRef(state, 'items'),
|
||||||
dismiss,
|
dismiss,
|
||||||
success: (message: string) => push(message, 'success'),
|
success: (message: string) => push(message, 'success'),
|
||||||
error: (message: string) => push(message, 'error'),
|
error: (message: string) => push(message, 'error'),
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import BaseEmptyState from '@/components/ui/BaseEmptyState.vue'
|
|||||||
import ActiveSwitchCell from '@/components/ui/ActiveSwitchCell.vue'
|
import ActiveSwitchCell from '@/components/ui/ActiveSwitchCell.vue'
|
||||||
import { companies as initialCompanies } from '@/data/mockData'
|
import { companies as initialCompanies } from '@/data/mockData'
|
||||||
import { useToast } from '@/composables/useToast'
|
import { useToast } from '@/composables/useToast'
|
||||||
|
import { confirm } from '@/composables/useConfirm'
|
||||||
import type { Company } from '@/types'
|
import type { Company } from '@/types'
|
||||||
|
|
||||||
const MAX_LOGO_SIZE = 2 * 1024 * 1024
|
const MAX_LOGO_SIZE = 2 * 1024 * 1024
|
||||||
@@ -95,7 +96,16 @@ function onLogoSelect(event: Event) {
|
|||||||
reader.readAsDataURL(file)
|
reader.readAsDataURL(file)
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeLogo() {
|
async function removeLogo() {
|
||||||
|
if (!logoPreview.value) return
|
||||||
|
const ok = await confirm({
|
||||||
|
title: 'حذف تصویر',
|
||||||
|
message: 'آیا از حذف لوگوی شرکت مطمئن هستید؟',
|
||||||
|
confirmLabel: 'حذف',
|
||||||
|
cancelLabel: 'انصراف',
|
||||||
|
tone: 'danger',
|
||||||
|
})
|
||||||
|
if (!ok) return
|
||||||
resetLogo()
|
resetLogo()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -71,8 +71,9 @@ const { checkDeadlines, dashboardStats, recentOrders, salesChartData, chartAxisL
|
|||||||
</div>
|
</div>
|
||||||
</RouterLink>
|
</RouterLink>
|
||||||
</div>
|
</div>
|
||||||
<button type="button" class="admin-link compact-dashboard__footer-link" @click="goOrders">
|
<button type="button" class="admin-btn admin-btn--primary admin-btn--sm compact-dashboard__footer-link" @click="goOrders">
|
||||||
مشاهده همه سفارشها
|
مشاهده همه سفارشها
|
||||||
|
<AdminIcon name="chevron-left" :size="16" />
|
||||||
</button>
|
</button>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
@@ -94,7 +95,10 @@ const { checkDeadlines, dashboardStats, recentOrders, salesChartData, chartAxisL
|
|||||||
<strong>{{ formatCurrency(item.amount) }}</strong>
|
<strong>{{ formatCurrency(item.amount) }}</strong>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<RouterLink to="/checks" class="admin-link compact-dashboard__footer-link">مشاهده همه</RouterLink>
|
<RouterLink to="/checks" class="admin-btn admin-btn--outline admin-btn--sm compact-dashboard__footer-link">
|
||||||
|
مشاهده همه
|
||||||
|
<AdminIcon name="chevron-left" :size="16" />
|
||||||
|
</RouterLink>
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -135,11 +139,9 @@ const { checkDeadlines, dashboardStats, recentOrders, salesChartData, chartAxisL
|
|||||||
}
|
}
|
||||||
|
|
||||||
.compact-dashboard__footer-link {
|
.compact-dashboard__footer-link {
|
||||||
display: inline-block;
|
display: inline-flex;
|
||||||
margin-top: 12px;
|
margin-top: 12px;
|
||||||
background: none;
|
text-decoration: none;
|
||||||
border: none;
|
|
||||||
padding: 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.compact-dashboard__deadlines {
|
.compact-dashboard__deadlines {
|
||||||
|
|||||||
@@ -94,7 +94,10 @@ const { checkDeadlines, dashboardStats, recentOrders, salesChartData, chartAxisL
|
|||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<div class="dashboard__card-footer">
|
<div class="dashboard__card-footer">
|
||||||
<button type="button" class="admin-link" @click="goOrders">مشاهده همه سفارشها</button>
|
<button type="button" class="admin-btn admin-btn--primary admin-btn--sm" @click="goOrders">
|
||||||
|
مشاهده همه سفارشها
|
||||||
|
<AdminIcon name="chevron-left" :size="16" />
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -119,7 +122,10 @@ const { checkDeadlines, dashboardStats, recentOrders, salesChartData, chartAxisL
|
|||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<div class="dashboard__card-footer">
|
<div class="dashboard__card-footer">
|
||||||
<RouterLink to="/checks" class="admin-link">مشاهده همه</RouterLink>
|
<RouterLink to="/checks" class="admin-btn admin-btn--outline admin-btn--sm">
|
||||||
|
مشاهده همه
|
||||||
|
<AdminIcon name="chevron-left" :size="16" />
|
||||||
|
</RouterLink>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -212,11 +218,17 @@ const { checkDeadlines, dashboardStats, recentOrders, salesChartData, chartAxisL
|
|||||||
}
|
}
|
||||||
|
|
||||||
.dashboard__card-footer {
|
.dashboard__card-footer {
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-start;
|
||||||
margin-top: 12px;
|
margin-top: 12px;
|
||||||
padding-top: 12px;
|
padding-top: 12px;
|
||||||
border-top: 1px solid var(--color-border-light);
|
border-top: 1px solid var(--color-border-light);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.dashboard__card-footer .admin-btn {
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
.dashboard__deadline-list {
|
.dashboard__deadline-list {
|
||||||
list-style: none;
|
list-style: none;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import AdminIcon from '@/components/icons/AdminIcon.vue'
|
|||||||
import StatusBadge from '@/components/ui/StatusBadge.vue'
|
import StatusBadge from '@/components/ui/StatusBadge.vue'
|
||||||
import { orders } from '@/data/mockData'
|
import { orders } from '@/data/mockData'
|
||||||
import { formatCurrency, formatNumber } from '@/utils/format'
|
import { formatCurrency, formatNumber } from '@/utils/format'
|
||||||
|
import { confirm } from '@/composables/useConfirm'
|
||||||
import type { OrderItem } from '@/types'
|
import type { OrderItem } from '@/types'
|
||||||
|
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
@@ -41,7 +42,18 @@ function goBack() {
|
|||||||
router.push('/orders')
|
router.push('/orders')
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeItem(id: string) {
|
async function removeItem(id: string) {
|
||||||
|
const item = items.value.find((entry) => entry.id === id)
|
||||||
|
const ok = await confirm({
|
||||||
|
title: 'حذف محصول',
|
||||||
|
message: item
|
||||||
|
? `آیا از حذف «${item.productName}» از سفارش مطمئن هستید؟`
|
||||||
|
: 'آیا از حذف این محصول از سفارش مطمئن هستید؟',
|
||||||
|
confirmLabel: 'حذف',
|
||||||
|
cancelLabel: 'انصراف',
|
||||||
|
tone: 'danger',
|
||||||
|
})
|
||||||
|
if (!ok) return
|
||||||
items.value = items.value.filter((i) => i.id !== id)
|
items.value = items.value.filter((i) => i.id !== id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user