Improve assignee and person pickers with search, chips and inline person creation
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -34,10 +34,12 @@ const props = withDefaults(
|
||||
defineProps<{
|
||||
embedded?: boolean;
|
||||
entityId?: string;
|
||||
/** متن جستجو برای پیشپر کردن نام یا موبایل شخص جدید */
|
||||
initialQuery?: string;
|
||||
}>(),
|
||||
{ embedded: false },
|
||||
);
|
||||
const emit = defineEmits<{ saved: []; cancel: [] }>();
|
||||
const emit = defineEmits<{ saved: [person?: PersonDto]; cancel: [] }>();
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
@@ -241,6 +243,8 @@ async function load() {
|
||||
if (!isNew.value && id.value) {
|
||||
const { data } = await api.get<PersonDto>(`/people/${id.value}`);
|
||||
fill(data);
|
||||
} else if (props.initialQuery?.trim()) {
|
||||
prefillFromQuery(props.initialQuery.trim());
|
||||
}
|
||||
} catch {
|
||||
error.value = 'بارگذاری فرم ناموفق بود.';
|
||||
@@ -249,6 +253,17 @@ async function load() {
|
||||
}
|
||||
}
|
||||
|
||||
function prefillFromQuery(text: string) {
|
||||
const digits = text.replace(/[۰-۹]/g, (d) => String('۰۱۲۳۴۵۶۷۸۹'.indexOf(d))).replace(/[\s-]/g, '');
|
||||
if (/^\+?\d{5,}$/.test(digits)) {
|
||||
mobile.value = digits;
|
||||
return;
|
||||
}
|
||||
const [first, ...rest] = text.split(/\s+/);
|
||||
firstName.value = first ?? '';
|
||||
lastName.value = rest.join(' ');
|
||||
}
|
||||
|
||||
function parseTags(raw: string): string[] {
|
||||
return [
|
||||
...new Set(
|
||||
@@ -287,7 +302,7 @@ async function submit() {
|
||||
if (isNew.value) {
|
||||
const { data } = await api.post<PersonDto>('/people', payload());
|
||||
if (props.embedded) {
|
||||
emit('saved');
|
||||
emit('saved', data);
|
||||
return;
|
||||
}
|
||||
await router.replace({ name: 'person-detail', params: { id: data.id } });
|
||||
|
||||
Reference in New Issue
Block a user