feat: send one SMS from a person or lead and keep the dashboard inside the phone frame

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-10-13 21:05:17 +03:30
co-authored by Cursor
parent 13ee70764b
commit 42f0573a5f
13 changed files with 733 additions and 113 deletions
@@ -1,11 +1,11 @@
<script setup lang="ts">
import { computed, onMounted, ref } from 'vue';
import { RouterLink } from 'vue-router';
import axios from 'axios';
import { api } from '@/lib/api';
import { toFaDigits } from '@/lib/jalali';
import UiIcon from '@/components/UiIcon.vue';
import { UiButton, UiModal, UiTextarea } from '@/components/ui';
import { UiButton, UiModal } from '@/components/ui';
import SmsComposeModal from '@/components/SmsComposeModal.vue';
type BirthdayItem = {
id: string;
@@ -13,6 +13,7 @@ type BirthdayItem = {
lastName: string;
fullName: string;
mobile: string | null;
company?: string;
day: number;
};
@@ -27,10 +28,6 @@ type BirthdayMonth = {
const data = ref<BirthdayMonth | null>(null);
const listOpen = ref(false);
const smsTarget = ref<BirthdayItem | null>(null);
const smsText = ref('');
const smsBusy = ref(false);
const smsError = ref('');
const smsDone = ref('');
const groups = computed(() => {
const map = new Map<number, BirthdayItem[]>();
@@ -42,34 +39,8 @@ const groups = computed(() => {
return [...map.entries()].sort((a, b) => a[0] - b[0]);
});
function apiMessage(e: unknown, fallback: string) {
if (!axios.isAxiosError(e)) return fallback;
const msg = (e.response?.data as { message?: string | string[] })?.message;
if (Array.isArray(msg)) return msg.join('، ') || fallback;
if (typeof msg === 'string' && msg.trim()) return msg;
return fallback;
}
function openSms(person: BirthdayItem) {
smsTarget.value = person;
smsText.value = `${person.fullName} عزیز، تولدتان مبارک.`;
smsError.value = '';
smsDone.value = '';
}
async function sendSms() {
const person = smsTarget.value;
if (!person || smsBusy.value) return;
smsBusy.value = true;
smsError.value = '';
try {
await api.post(`/people/${person.id}/birthday-sms`, { text: smsText.value });
smsDone.value = `پیامک برای ${person.fullName} ارسال شد.`;
} catch (e) {
smsError.value = apiMessage(e, 'ارسال پیامک ناموفق بود.');
} finally {
smsBusy.value = false;
}
}
onMounted(async () => {
@@ -97,22 +68,28 @@ onMounted(async () => {
v-for="person in data.preview"
:key="person.id"
class="chip"
:title="person.fullName"
:to="{ name: 'person-detail', params: { id: person.id } }"
>
<b>{{ toFaDigits(person.day) }} {{ data.monthName }}</b>
<b>{{ toFaDigits(person.day) }}</b>
<span>{{ person.fullName }}</span>
</RouterLink>
<button v-if="data.total > data.preview.length" type="button" class="more" @click="listOpen = true">
همه
</button>
<button v-else type="button" class="more" @click="listOpen = true">فهرست و پیامک</button>
</div>
<button type="button" class="more" @click="listOpen = true">
{{ data.total > data.preview.length ? 'همه' : 'فهرست' }}
</button>
<UiModal :open="listOpen" :title="`تولدهای ${data.monthName}`" @close="listOpen = false">
<div class="days">
<section v-for="[day, people] in groups" :key="day" class="day">
<section
v-for="[day, people] in groups"
:key="day"
class="day"
:class="{ past: day < data.today, today: day === data.today }"
>
<h3>
{{ toFaDigits(day) }} {{ data.monthName }}
<b>{{ toFaDigits(day) }}</b>
<span>{{ data.monthName }}</span>
<em v-if="day < data.today">گذشته</em>
<em v-else-if="day === data.today">امروز</em>
</h3>
@@ -121,38 +98,32 @@ onMounted(async () => {
<RouterLink :to="{ name: 'person-detail', params: { id: person.id } }" @click="listOpen = false">
{{ person.fullName }}
</RouterLink>
<UiButton
size="sm"
variant="outline"
<button
type="button"
class="sms"
:disabled="!person.mobile"
@click="openSms(person)"
>
{{ person.mobile ? 'پیامک تبریک' : 'بدون شماره' }}
</UiButton>
</button>
</li>
</ul>
</section>
</div>
</UiModal>
<UiModal
:open="!!smsTarget"
<SmsComposeModal
nest
:open="!!smsTarget"
title="پیامک تبریک تولد"
:endpoint="smsTarget ? `/people/${smsTarget.id}/birthday-sms` : ''"
default-text="{نام} عزیز، تولدتان مبارک."
:name="smsTarget?.fullName ?? ''"
:phone="smsTarget?.mobile ?? ''"
:record-title="smsTarget?.fullName ?? ''"
:company="smsTarget?.company ?? ''"
@close="smsTarget = null"
>
<p v-if="smsTarget" class="lead">برای {{ smsTarget.fullName }}</p>
<UiTextarea v-model="smsText" :rows="4" />
<p class="hint">می‌توانید متن را عوض کنید. عبارت {نام} با نام مشتری جایگزین می‌شود.</p>
<p v-if="smsError" class="err">{{ smsError }}</p>
<p v-if="smsDone" class="ok">{{ smsDone }}</p>
<template #footer>
<UiButton variant="ghost" :disabled="smsBusy" @click="smsTarget = null">بستن</UiButton>
<UiButton variant="primary" :loading="smsBusy" :disabled="smsBusy || !smsText.trim() || !!smsDone" @click="sendSms">
ارسال پیامک
</UiButton>
</template>
</UiModal>
/>
</section>
</template>
@@ -160,112 +131,223 @@ onMounted(async () => {
.birthdays {
display: flex;
align-items: center;
gap: 1rem;
background: #fff;
border: 1px solid #eef2f7;
gap: 0.75rem;
min-width: 0;
max-width: 100%;
background:
linear-gradient(90deg, rgba(255, 255, 255, 0.35), transparent 42%),
linear-gradient(100deg, var(--accent-subtle) 0%, #fff 58%, #fff7f4 100%);
border: 1px solid color-mix(in srgb, var(--accent) 22%, #fff);
border-radius: var(--radius);
box-shadow: 0 8px 24px rgba(15, 23, 42, 0.04);
padding: 0.85rem 1rem;
box-shadow: 0 6px 18px rgba(15, 118, 110, 0.05);
padding: 0.55rem 0.75rem;
}
.head {
display: flex;
align-items: center;
gap: 0.7rem;
gap: 0.55rem;
flex-shrink: 0;
}
.ico {
width: 40px;
height: 40px;
border-radius: 12px;
width: 32px;
height: 32px;
border-radius: 10px;
display: grid;
place-items: center;
background: #fff7ed;
color: #ea580c;
background: #fff;
color: #e11d48;
box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 18%, #fff);
}
.head strong {
display: block;
color: #0f172a;
color: var(--accent-deep);
font-size: 0.88rem;
font-weight: 700;
}
.head p {
margin: 0.15rem 0 0;
color: #94a3b8;
font-size: 0.82rem;
margin: 0.05rem 0 0;
color: #64748b;
font-size: 0.75rem;
}
.chips {
display: flex;
flex-wrap: wrap;
gap: 0.45rem;
flex: 1 1 auto;
flex-wrap: nowrap;
gap: 0.35rem;
min-width: 0;
max-width: 100%;
overflow: hidden;
}
.chip,
.more {
.chip {
display: inline-flex;
flex-shrink: 0;
align-items: center;
gap: 0.4rem;
gap: 0.35rem;
max-width: 11.5rem;
min-width: 0;
border-radius: 999px;
border: 1px solid #fed7aa;
background: #fff7ed;
color: #9a3412;
padding: 0.35rem 0.7rem;
border: 1px solid color-mix(in srgb, var(--accent) 24%, #fff);
background: rgba(255, 255, 255, 0.86);
color: #134e4a;
padding: 0.22rem 0.55rem 0.22rem 0.28rem;
text-decoration: none;
font: inherit;
cursor: pointer;
font-size: 0.78rem;
}
.chip b {
flex-shrink: 0;
font-weight: 700;
font-size: 0.72rem;
color: var(--accent-deep);
background: var(--accent-soft);
border-radius: 999px;
padding: 0.12rem 0.38rem;
}
.chip span {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.more {
background: #0f172a;
border-color: #0f172a;
flex-shrink: 0;
border: 0;
border-radius: 999px;
background: var(--accent);
color: #fff;
padding: 0.32rem 0.7rem;
font: inherit;
font-size: 0.78rem;
cursor: pointer;
}
.more:hover {
background: var(--accent-hover);
}
.days {
display: grid;
gap: 0.9rem;
max-height: 60vh;
gap: 0.85rem;
max-height: 62vh;
overflow: auto;
padding-inline-end: 0.15rem;
}
.day {
background: #fff;
border: 1px solid #e7eef2;
border-radius: 14px;
overflow: hidden;
}
.day h3 {
margin: 0 0 0.4rem;
font-size: 0.92rem;
color: #0f172a;
display: flex;
align-items: center;
gap: 0.4rem;
margin: 0;
padding: 0.55rem 0.8rem;
background: var(--accent-subtle);
border-bottom: 1px solid color-mix(in srgb, var(--accent) 16%, #fff);
font-size: 0.86rem;
font-weight: 600;
color: var(--accent-deep);
}
.day h3 b {
display: grid;
place-items: center;
min-width: 1.7rem;
height: 1.7rem;
padding: 0 0.3rem;
border-radius: 999px;
background: var(--accent);
color: #fff;
font-size: 0.78rem;
}
.day em {
margin-inline-start: 0.4rem;
margin-inline-start: auto;
font-style: normal;
font-size: 0.75rem;
font-size: 0.72rem;
font-weight: 600;
color: #94a3b8;
background: #fff;
border-radius: 999px;
padding: 0.1rem 0.45rem;
}
.day.today h3 {
background: color-mix(in srgb, var(--accent-soft) 70%, #fff);
}
.day.today em {
color: var(--accent-deep);
}
.day.past {
opacity: 0.82;
}
.day ul {
list-style: none;
margin: 0;
padding: 0;
display: grid;
gap: 0.35rem;
}
.day li {
display: flex;
align-items: center;
justify-content: space-between;
gap: 0.6rem;
gap: 0.75rem;
padding: 0.62rem 0.85rem;
border-top: 1px solid #eef2f6;
}
.day li:first-child {
border-top: 0;
}
.day a {
flex: 1 1 auto;
color: #0f172a;
text-decoration: none;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.day a:hover {
color: var(--accent-deep);
}
.sms {
flex-shrink: 0;
border: 1px solid color-mix(in srgb, var(--accent) 35%, #fff);
background: #fff;
color: var(--accent-deep);
border-radius: 999px;
padding: 0.28rem 0.65rem;
font: inherit;
font-size: 0.75rem;
cursor: pointer;
}
.sms:hover:not(:disabled) {
background: var(--accent-subtle);
}
.sms:disabled {
border-color: #e2e8f0;
color: #94a3b8;
cursor: default;
}
.lead {
@@ -293,8 +375,40 @@ onMounted(async () => {
@media (max-width: 720px) {
.birthdays {
align-items: flex-start;
flex-direction: column;
display: grid;
grid-template-columns: minmax(0, 1fr) auto;
align-items: center;
gap: 0.45rem 0.6rem;
}
.head {
min-width: 0;
}
.head p {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.more {
grid-column: 2;
grid-row: 1;
}
.chips {
grid-column: 1 / -1;
overflow-x: auto;
scrollbar-width: none;
}
.chips::-webkit-scrollbar {
display: none;
}
.day li {
gap: 0.45rem;
padding-inline: 0.7rem;
}
}
</style>
+23 -5
View File
@@ -199,8 +199,10 @@ const shortcutLabel = computed(() =>
.hero-body {
display: grid;
grid-template-columns: minmax(0, 1fr);
gap: 0.75rem;
min-width: 0;
max-width: 100%;
padding-top: 0;
}
@@ -208,6 +210,12 @@ const shortcutLabel = computed(() =>
display: flex;
align-items: center;
gap: 0.9rem;
min-width: 0;
max-width: 100%;
}
.greet-text {
min-width: 0;
}
.hero-avatar {
@@ -261,7 +269,8 @@ const shortcutLabel = computed(() =>
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 0.4rem;
max-width: 580px;
max-width: min(580px, 100%);
min-width: 0;
}
.chip {
@@ -330,8 +339,9 @@ const shortcutLabel = computed(() =>
.hero-ask-wrap {
display: grid;
gap: 0.45rem;
max-width: 520px;
max-width: min(520px, 100%);
width: 100%;
min-width: 0;
}
.hero-ask {
@@ -339,6 +349,8 @@ const shortcutLabel = computed(() =>
align-items: center;
gap: 0.55rem;
width: 100%;
min-width: 0;
max-width: 100%;
background: #fff;
color: #0f172a;
border-radius: 999px;
@@ -425,19 +437,25 @@ const shortcutLabel = computed(() =>
}
.hero-chips {
grid-template-columns: 1fr;
max-width: 420px;
grid-template-columns: minmax(0, 1fr);
max-width: min(420px, 100%);
}
}
@media (max-width: 700px) {
.hero {
grid-template-columns: 1fr;
grid-template-columns: minmax(0, 1fr);
min-height: auto;
padding-inline: 0.85rem;
overflow: hidden;
}
.hero-bot {
display: none;
}
.hero-ask kbd {
display: none;
}
}
</style>