Align Leads header with Contacts and add phone-contact lead import.
Leads actions mirror people import/export, and create-lead can fill fields from device contacts like Person form.
This commit is contained in:
@@ -15,9 +15,14 @@ import {
|
||||
type PhoneContactDraft,
|
||||
} from '@/lib/phone-contacts';
|
||||
|
||||
defineProps<{
|
||||
disabled?: boolean;
|
||||
}>();
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
disabled?: boolean;
|
||||
/** people = اشخاص | leads = لیدها */
|
||||
target?: 'people' | 'leads';
|
||||
}>(),
|
||||
{ target: 'people' },
|
||||
);
|
||||
|
||||
const emit = defineEmits<{
|
||||
start: [];
|
||||
@@ -171,15 +176,30 @@ async function importSelected() {
|
||||
let failed = 0;
|
||||
try {
|
||||
for (const row of rows) {
|
||||
const body: CreatePersonRequest = {
|
||||
firstName: row.firstName,
|
||||
lastName: row.lastName || undefined,
|
||||
mobile: row.mobile,
|
||||
phone: row.phone,
|
||||
email: row.email,
|
||||
};
|
||||
try {
|
||||
await api.post<PersonDto>('/people', body);
|
||||
if (props.target === 'leads') {
|
||||
const mobile = row.mobile || row.phone;
|
||||
if (!mobile) {
|
||||
failed += 1;
|
||||
continue;
|
||||
}
|
||||
await api.post('/leads', {
|
||||
title: row.fullName,
|
||||
contactName: row.fullName,
|
||||
mobile,
|
||||
phone: row.phone && row.phone !== mobile ? row.phone : null,
|
||||
source: 'مخاطبین گوشی',
|
||||
});
|
||||
} else {
|
||||
const body: CreatePersonRequest = {
|
||||
firstName: row.firstName,
|
||||
lastName: row.lastName || undefined,
|
||||
mobile: row.mobile,
|
||||
phone: row.phone,
|
||||
email: row.email,
|
||||
};
|
||||
await api.post<PersonDto>('/people', body);
|
||||
}
|
||||
created += 1;
|
||||
} catch (e) {
|
||||
if (axios.isAxiosError(e) && e.response?.status === 409) {
|
||||
@@ -315,7 +335,8 @@ async function importSelected() {
|
||||
@click="importSelected"
|
||||
>
|
||||
<UiIcon name="user-plus" :size="16" />
|
||||
ورود {{ toFaDigits(selectedCount) }} نفر
|
||||
ورود {{ toFaDigits(selectedCount) }}
|
||||
{{ target === 'leads' ? 'لید' : 'نفر' }}
|
||||
</UiButton>
|
||||
</template>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user