Explore hi Save Share Download ▾ ReportJump to turn (14) 1 hi 2 انت مبرمج محترف في البرمجة باستخدام Vue3 , frppe-ui ,pinia, tailwindcss وانا اري 3 (empty prompt) 4 (empty prompt) 5 (empty prompt) 6 اريد منك ان تعيد الكود الكامل لكل ملف بعد التعديل 7 (empty prompt) 8 (empty prompt) 9 (empty prompt) 10 اريد منك ان ترجع لي الكود الكامل لكل ملف بعد التعديل 11 واجهني خاء في كود الصفحة step1.vue في الدالة ولذي سوف ارسل لك نص هذا الخطاء 12 (empty prompt) 13 تم اضافة بيانات aliasname الى store ولاكن لم يتم اضافتها الى الجدول الفرعي الموج 14 اريد ان يتم التعامل مع aliasname مثل التعامل مع educationinformation Assistant2024-10-24 21:20 UTC Copy response
Hello! How can I assist you today?
انت مبرمج محترف في البرمجة باستخدام Vue3 , frppe-ui ,pinia, tailwindcss وانا اريد منك مساعدتي في مشروعي ولذي سوف الذي سوف اشرحه لك الان , لدي صفحة باسم step1.vue ولتي سوف ارسل لك الكود الخاص بها وهذه الصفحة يتم من خلالهاادخال بيانات لمجموعه من الحقول ومن ضمن هذه الحقول حقل[ Country,City,Governorate] وغيرها من الحقول وايضا يتم من خلال هذه الواجهه اتاحة للمستخدم في اضافة اكثر من رقم هاتف وكذالك اضافه اكثر من اسم مستعار مع العلم ان كل من phone , Alias Name هي عباره عن Child Table في ال Doctype الاب Verification Instructions Request ومع العلم ان الجدول الفرعي Alias Name يحتوي على الحقول الاتية [first_name,middle_name,last_name] و الجدول الفرعي phone يحتول على حقل [phone] , ومع العلم انا لدي ملف src/stores/verificationRequest.ts وسوف ارسل لك محتواه وانا ايضن src/data/types.ts استخدم ملف وسوف ارسل لك محتوه , واريد مساعدتك في برمجة اضافة phone وكذالك برمجة اظافة ال Alias Name , الى الجداول الفرعية المتواجده في ال Doctype الاب Verification Instructions Request ,الان اريد منك انا تخبرني كيف ابداء بارسال محتواء الملفات اليك وماهي الخطوات التي اتبعها للتعامل معك , المخرجات اريد ان تكون مخرجات كود كل ملف بعد التعديل وشرح للتعديلات.
Copy first prompt Copy first response
Other models, same or similar prompt Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Details
Provider OpenAI
Model provenance As recorded by source dataset
Turns 14 (28 messages)
Language en
Conversation date Oct 24, 2024
Added to archive Nov 16, 2026
ID 01m7h4219v2j7yjkqkh5xx046tSource & license Imported from WildChat-4.8M (AI2) (source ). Imported records earn no Research Points.
Upstream record: 079eda557cb5817b4e5dbc6b93d8a1d7
Zhao et al., WildChat: 1M ChatGPT Interaction Logs in the Wild (ICLR 2024). Contains information from WildChat-4.8M, made available under the ODC Attribution License.
License: ODC-BY-1.0
Assistant2024-10-24 21:20 UTC Copy response
بالتأكيد، يمكنني مساعدتك في مشروعك! لبدء العمل، يمكنك اتباع الخطوات التالية:
إرسال محتوى الملفات : ابدأ بإرسال محتوى الملفات التي ترغب في تعديلها، مثل step1.vue وverificationRequest.ts وtypes.ts. يمكنك لصق الكود مباشرة في المحادثة هنا.
شرح حول التعديلات المطلوبة : كجزء من رسالتك، يرجى توضيح المتطلبات الدقيقة لما تريد تعديله أو إضافته. على سبيل المثال، إذا كنت ترغب في إضافة وظائف لإضافة أرقام هواتف أو أسماء مستعارة، يرجى توضيح ذلك.
التعديلات في الملفات : بعد أن أستلم محتوى الملفات ومتطلباتك، سأقوم بمراجعة الكود وسأقترح التعديلات اللازمة مع توضيح لكل تعديل.
المخرجات : سأزودك بكود كل ملف بعد التعديل وسأشرح لك كل تعديل قمت به.
يمكنك البدء الآن بإرسال المحتوى وسأكون هنا لمساعدتك!
Show full message · 600 lines Assistant2024-10-24 21:21 UTC Copy response
شكرًا لمشاركة كود Vue الخاص بك! سأساعدك في دمج وظائف إضافة أرقام الهواتف وأسماء مستعارة في مكون step1.vue وتخزينها بشكل مناسب باستخدام Pinia.
الخطوات المطلوبة:
تعديل src/stores/verificationRequest.ts : سنضيف وظائف مخصصة لإدارة البيانات في المتجر (store) لـ phone و alias name.
تعديل src/data/types.ts (إذا لزم الأمر) : إذا كان لديك أنماط مخصصة لأرقام الهواتف أو أسماء المستعارة، قد تحتاج إلى تعديل هذا الملف.
سأبدأ بالجزء الأول: تحديث verificationRequest.ts. إذا كان لديك الملف، يرجى مشاركته، وسأقوم بإجراء التعديلات المطلوبة.
1. تحديث verificationRequest.ts
إذا كان محتوى هذا الملف يحتوي على تخزين البيانات لهذه الحقول، يمكننا إضافة وظائف لإدارة هذه البيانات. إليك مثال على ما تحتاجه:
typescript Copy code
import { defineStore } from 'pinia';
export const useVerificationRequestStore = defineStore('verificationRequest', {
state: () => ({
step1: {
// ... الحقول الأخرى,
phone: [],
alias_name: []
},
}),
actions: {
updatePhoneNumber(index: number, value: string) {
this.step1.phone[index] = { phone: value };
},
updateAliasName(index: number, value: { first_name: string; middle_name?: string; last_name: string; }) {
this.step1.alias_name[index] = value;
},
async saveStep1() {
// قم بإجراء الطلب إلى API لحفظ البيانات
const payload = {
...this.step1,
};
console.log("Saving data...", payload);
// تأكد من تنفيذ الطلب بشكل صحيح هنا
}
}
});
2. تحديث types.ts
إذا كان لديك types.ts، يمكننا إضافة الأنماط المناسبة لأرقام الهواتف وأسماء المستعارة:
typescript Copy code
export interface PhoneNumber {
phone: string;
}
export interface AliasName {
first_name: string;
middle_name?: string;
last_name: string;
}
الآن بعدما قمت بإظهار كيفية تعديل verificationRequest.ts و types.ts، يمكنك تأكيد إذا كان هذا هو الشكل الذي ترغب به، وسأواصل شرح كيفية دمجها في الكود الخاص بك. إذا كان لديك محتوى خاص بهذه الملفات، يرجى مشاركتها كما فعلت مع step1.vue.
Show full message · 177 lines Assistant2024-10-24 21:22 UTC Copy response
شكرًا لمشاركة جزء من كود verificationRequest.ts. سأساعدك في دمج وظائف حفظ واسترجاع phone و alias_name في هذا الكود.
التعديلات المطلوبة:
تحديث دالة loadStep1Fields : التأكد من أنه يتم تحميل البيانات بشكل صحيح من قاعدة البيانات للحقول الفرعية (phone و alias name).
إضافة دوال updatePhone و updateAliasName : هذه الدوال ستقوم بتحديث الحقول في المتجر.
تحديث دالة saveStep1 : لتشمل الحقول الفرعية عند حفظ البيانات.
تعديل verificationRequest.ts
إليك التعديلات المقترحة:
Show full message · 190 lines Assistant2024-10-24 21:23 UTC Copy response
شكرًا لمشاركة ملف types.ts. يحتوي هذا الملف على تعريفات الأنواع التي ستساعدنا في تحسين إدارة البيانات في مشروعك. دعنا نوضح كيفية دمج الـ phones وalias names في هذا الملف بشكل مناسب والحرص على أن تكون البيانات متوافقة مع التنفيذ السابق الذي قمت به.
تعديلات على types.ts
تأكد من أن واجهة PhoneNumber وAliasName متوافقة مع البيانات. الحقول يجب أن تشمل الـ id، phone، وأي تفاصيل أخرى تحتاج إليها للأسماء المستعارة.
تأكد من تحديث واجهة Step1Data لتشمل phone وalias_name كقوائم من الأشياء. للـ alias_name، سيتضمن حقول الـ first_name، middle_name، وlast_name.
إليك كيفية تعديل types.ts
لذا تأكد من أن types.ts يبدو هكذا:
typescript Copy code
// واجهة لحقل النموذج
export interface FormField<T = any> {
value: T;
isValid: boolean;
validationMessage: string;
touched?: boolean;
}
export interface PhoneNumber {
id: string; // تأكد من وجود معرف فريد لكل رقم
phone: string;
}
export interface AliasName {
id: string; // تأكد من وجود معرف فريد لكل اسم مستعار
first_name: string;
last_name: string;
middle_name: string;
}
export interface Step1Data {
employer_name: FormField<string>;
first_name: FormField<string>;
last_name: FormField<string>;
dont_middle_name: FormField<boolean>;
middle_name: FormField<string>;
this_is_my_name_column: FormField<boolean>;
suffix: FormField<string>;
alias_name: AliasName[]; // صيغة القائمة
country_now: FormField<string>;
city: FormField<string>;
governorate: FormField<string>;
zip_code: FormField<string>;
location_text: FormField<string>;
street_address: FormField<string>;
date_living_address: FormField<string>;
phone: PhoneNumber[]; // صيغة القائمة
email: FormField<string>;
date_of_birth: FormField<string>;
}
// ... باقي الأنواع تبقى كما هي
تحديث التعديلات
تأكد من إضافة id في واجهتي PhoneNumber و AliasName : هذا سيساعدك على تحديد كل رقم هاتف أو اسم مستعار بسهولة عند الحذف أو التعديل.
وضعت alias_name و phone كقوائم : هذا يضمن أن البيانات تتكدس بشكل صحيح في Step1Data، ويسهل التعامل معها.
الخطوة التالية:
بعد إجراء هذه التعديلات، يمكنك استخدام الأنواع الخاصة بك بشكل موثوق في كود step1.vue وكذلك في verificationRequest.ts. إذا كان لديك أي المزيد من الأسئلة أو تحتاج إلى تعديلات إضافية، فلا تتردد في إخباري!
اريد منك ان تعيد الكود الكامل لكل ملف بعد التعديل
Assistant2024-10-24 21:29 UTC Copy response
بالطبع! سأجمع التعديلات التي قمنا بها وأعيد لك الكود الكامل لكل ملف بعد التعديل. إليك الأكواد لكل من الملفات step1.vue وverificationRequest.ts وtypes.ts.
1. ملف step1.vue
Show full message · 366 lines Show full message · 600 lines Assistant2024-10-24 21:51 UTC Copy response
ها هو الكود الكامل المحدث لملف step1.vue بعد دمج جميع التعديلات التي ناقشناها، بما في ذلك التعامل مع أرقام الهواتف وأسماء المستعارة. إليك الإصدار الكامل:
Show full message · 588 lines Show full message · 770 lines Assistant2024-10-24 21:53 UTC Copy response
هنا هو الكود الكامل لملف verificationRequest.ts بعد التعديلات اللازمة، بما في ذلك التعامل مع بيانات الهاتف وأسماء المستعارة:
Show full message · 453 lines Show full message · 190 lines Assistant2024-10-24 21:54 UTC Copy response
إليك الكود الكامل المحدث لملف types.ts بعد دمج جميع التعديلات المطلوبة، بما في ذلك التعامل مع أرقام الهواتف وأسماء المستعارة:
Show full message · 204 lines اريد منك ان ترجع لي الكود الكامل لكل ملف بعد التعديل
Assistant2024-10-24 22:14 UTC Copy response
بالطبع! إليك الكود الكامل المحدث لكل من الملفات التي تم تعديلها في مشروعك:
1. ملف step1.vue
Show full message · 1,160 lines واجهني خاء في كود الصفحة step1.vue في الدالة const addPhoneNumber = () => { phoneNumbers.value.push({ id: uuidv4(), phone: '' }); }; ولذي سوف ارسل لك نص هذا الخطاء
Assistant2024-10-24 22:27 UTC Copy response
بالطبع، يمكنك مشاركة نص الخطأ الذي واجهته وسأكون سعيدًا بمساعدتك في إصلاحه. من الجيد أيضًا أن تتأكد من أنك قد استوردت المكتبة الضرورية لـ uuidv4 بشكل صحيح، والتي تستخدم لتوليد معرفات فريدة. ينبغي أن يكون لديك:
javascript Copy code
import { v4 as uuidv4 } from 'uuid';
يرجى إرسال نص الخطأ وسأقوم بتحليله.
Object Copy code
(property) id: any ```
Assistant2024-10-24 22:28 UTC Copy response
يبدو أن المشكلة تتعلق بعدم توافق نوع الكائن الذي تحاول إضافته إلى phoneNumbers.value. الخطأ يشير إلى أن TypeScript لا يعرف خاصية id في الكائن الذي تُضيفه، ويفترض أنه يتوافق فقط مع النوع { phone: string }.
الحل
لكي نقوم بإصلاح هذه المشكلة، يجب علينا التأكد من أن الكائن الذي نضيفه إلى phoneNumbers يتوافق مع الواجهة PhoneNumber التي عرّفناها في types.ts.
كيفية حل المشكلة
تأكد من أن PhoneNumber تتضمن الخاصية id :
تأكد من أن لديك واجهة PhoneNumber الصحيحة في types.ts. يجب أن تحتوي على الحقول id و phone.
typescript Copy code
export interface PhoneNumber {
id: string; // معرف فريد لكل رقم هاتف
phone: string; // رقم الهاتف
}
تعديل الدالة addPhoneNumber لإضافة نوع الهاتف بشكل صحيح :
تأكد من أن الكائن الذي تضيفه يتوافق مع PhoneNumber. يمكنك استخدام التعيينات بشكل مباشر:
javascript Copy code
const addPhoneNumber = () => {
phoneNumbers.value.push({ id: uuidv4(), phone: '' } as PhoneNumber);
};
يمكنك أيضًا التأكد من أن بداية phoneNumbers تم تعريفها بالشكل الصحيح:
javascript Copy code
const phoneNumbers = ref<PhoneNumber[]>([{ id: uuidv4(), phone: '' }]);
الكود النهائي بعد التعديلات
إليك كيفية تحديث القسم ذات الصلة في step1.vue:
javascript Copy code
import { v4 as uuidv4 } from 'uuid'; // تأكد من الاستيراد
// تعريف المتغيرات
const phoneNumbers = ref<PhoneNumber[]>([{ id: uuidv4(), phone: '' }]); // تأكد من أن لديك معرف فريد هنا
const addPhoneNumber = () => {
phoneNumbers.value.push({ id: uuidv4(), phone: '' } as PhoneNumber); // استخدم تحويل النوع
};
// الدوال الأخرى هنا...
إذا استمر الخطأ:
إذا استمر الخطأ، يمكنك إخباري وسأكون سعيدًا بمساعدتك في استكشاف المشكلة بشكل أعمق!
تم اضافة بيانات alias_name الى store ولاكن لم يتم اضافتها الى الجدول الفرعي الموجود في Doctype اما phone فلم يتم اضافتها الى store ولا الى الجدول الفرعي الموجود في Doctype
Assistant2024-10-24 22:59 UTC Copy response
لإضافة البيانات الخاصة بأرقام الهواتف وأسماء المستعارة إلى store وكذلك إلى الجدول الفرعي الموجود في Doctype، يجب التأكد من تنفيذ بعض الخطوات الأساسية. دعنا نراجع الكود الذي تحتاج إلى تعديله لضمان أن البيانات تُضاف وتُحفظ بشكل صحيح.
الخطوات المطلوب القيام بها:
تحديث دوال الحفظ لإضافة البيانات للجدول الفرعي .
التأكد من أن واجهات Pinia تتضمن جميع الحقول المطلوبة .
التأكد من أن البيانات تُرسل بشكل صحيح أثناء عمليات الحفظ .
1. تحديث دوال الحفظ
لإضافة أسماء المستعارة
تأكد من أن لديك دالة في verificationRequest.ts لحفظ alias_name إلى Doctype:
typescript Copy code
async saveStep1() {
const toast = useToast();
if (!this.validateStep1()) {
toast.error('يرجى تصحيح الأخطاء قبل الحفظ.');
throw new Error('Validation failed');
}
const dataToSubmit: UpdateFields = {
// قم بإضافة أسماء المستعارة هنا
alias_name: this.step1.alias_name,
phone: this.step1.phone, // إضافة أرقام الهواتف
};
for (const key in this.step1) {
if (Object.prototype.hasOwnProperty.call(this.step1, key)) {
const field = key as keyof Step1Data;
dataToSubmit[key] = this.step1[field].value;
}
}
try {
await this.updateDocumentFields(dataToSubmit);
toast.success('تم حفظ البيانات بنجاح.');
} catch (error) {
throw error;
}
}
لإضافة أرقام الهواتف
تأكد من أن لديك dataToSubmit تم تمريرها بالكمية الصحيحة في دالة الحفظ وتحتوي على أرقام الهواتف.
2. تحديث واجهات Pinia
تأكد من أن واجهة Step1Data في types.ts تحتوي على الحقول الصحيحة لأرقام الهواتف وأسماء المستعارة.
3. إضافة البيانات إلى الجدول الفرعي
عندما تحفظ بيانات Step1، تأكد من أن تضع المنطق لإضافتها إلى الجدول الفرعي في الـ Doctype الخاص بك. تأكد أيضًا من أن الـ API أو الدالة التي تحفظ البيانات في فريبي (Frappe) تدعم الحفاظ على الحقول الفرعية (child tables).
مثال توضيحي
إليك مثال مبسط لتوضيح كيفية تحديث بيانات الأسماء المستعارة وأرقام الهواتف:
اريد ان يتم التعامل مع alias_name مثل التعامل مع education_information
Assistant2024-10-24 23:22 UTC Copy response
لجعل التعامل مع alias_name مشابهًا لكيفية معالجة education_information في مشروعك، فإنك بحاجة إلى إجراء بعض التعديلات على كيفية تنظيم البيانات وتحديثها، بالإضافة إلى طريقة حفظها.
الخطوات المقترحة:
إعادة الهيكلة : مشابهة لهيكلة education_information، اجعل alias_name قائمة من الكائنات مع خصائص محددة.
إضافة دوال لعمليات CRUD : أنشئ دوال لإضافة، حذف، وتحديث أسماء المستعارة، كما هو الحال مع المعلومات التعليمية.
تحديث دالة saveStep1 : تأكد من تضمين alias_name عند حفظ البيانات إلى الـ Doctype.
الخطوات التفصيلية
1. تعديل واجهات الـ TypeScript
تأكد من أن لديك واجهة education_information و alias_name متشابهة في النوع:
typescript Copy code
export interface AliasName {
id: string; // معرف فريد لكل اسم مستعار
first_name: string; // الاسم الأول
last_name: string; // اسم العائلة
middle_name: string; // الاسم الأوسط
}
export interface Step1Data {
...
alias_name: AliasName[]; // لضمان أنها قائمة من الكائنات
...
}
2. تحديث دوال التحكم
قم بإنشاء دوال لإضافة وحذف وتحديث الأسماء المستعارة بشكل مماثل لكيفية تنفيذ التعليم:
typescript Copy code
// إضافة اسم مستعار جديد
addAliasName() {
this.step1.alias_name.push({ id: uuidv4(), first_name: '', last_name: '', middle_name: '' });
},
// إزالة اسم مستعار
removeAliasName(index: number) {
this.step1.alias_name.splice(index, 1);
},
// تحديث اسم مستعار
updateAliasName(index: number, newValues: { first_name: string; last_name: string; middle_name: string }) {
this.step1.alias_name[index] = { ...this.step1.alias_name[index], ...newValues };
},
3. تضمين alias_name في saveStep1
تأكد من أن دالة الحفظ تشمل alias_name عند إرسال البيانات:
Not yet included in a published release.
<!-- /pages/stepsSections/step1.vue -->
<template>
<div class="pt-3 container">
<h1 class="text-3xl font-bold mb-3 text-black">Personal Information</h1>
<ul>
<li>All fields marked with an asterisk ( * ) are required.</li>
<li>Providing your information as completely and accurately as possible will help speed up the completion of your Background Verification</li>
</ul>
<div class="lg:grid grid-rows-2 lg:gap-2">
<h1 class="text-lg font-medium mb-1 mt-4 text-black">Name</h1>
<Info
text="Please provide your name exactly as it appears on your current government-issued identification document such as your Passport, Driver’s License or National Identification Document"
/>
</div>
<div class="lg:grid grid-cols-2 lg:gap-2">
<FieldContainer>
<StyledInput
labelText="Employer Name"
:isMandatory="true"
infoText="Employer Name"
inputType="text"
v-model="employerName"
:isValid="store.step1.employer_name.isValid"
:validationMessage="store.step1.employer_name.validationMessage"
name="employer_name"
id="EmployerName"
/>
<SupportingText>Supporting text</SupportingText>
</FieldContainer>
<FieldContainer>
<StyledInput
labelText="First Name"
:isMandatory="true"
infoText="First Name"
inputType="text"
v-model="firstName"
:isValid="store.step1.first_name.isValid"
:validationMessage="store.step1.first_name.validationMessage"
name="first_name"
id="firstName"
/>
</FieldContainer>
</div>
<FieldContainer>
<CheckBox
name="dont_middle_name"
id="dont_middle_name"
v-model="dontMiddleName"
>
I certify that I do not have a Middle Name on my official identification document
</CheckBox>
</FieldContainer>
<div class="lg:grid grid-cols-2 lg:gap-2">
<FieldContainer v-if="!dontMiddleName">
<StyledInput
labelText="Middle Name"
inputType="text"
v-model="middleName"
:isValid="store.step1.middle_name.isValid"
:validationMessage="store.step1.middle_name.validationMessage"
name="middle_name"
id="MiddleName"
/>
</FieldContainer>
</div>
<div class="lg:grid grid-cols-2 lg:gap-2">
<FieldContainer>
<StyledInput
labelText="Last Name"
:isMandatory="true"
infoText="Last Name"
inputType="text"
v-model="lastName"
:isValid="store.step1.last_name.isValid"
:validationMessage="store.step1.last_name.validationMessage"
name="last_name"
id="lastName"
/>
</FieldContainer>
<FieldContainer>
<Autocomp
id="suffix"
name="suffix"
labelText="Suffix"
infoText="Select your suffix"
inputType="text"
:options="suffixOptions"
@input-change="handleSuffix"
v-model="suffix"
:isValid="store.step1.suffix.isValid"
:validationMessage="store.step1.suffix.validationMessage"
/>
</FieldContainer>
</div>
<div class="lg:grid grid-cols-2 lg:gap-2">
<FieldContainer>
<Autocomp
name="country_now"
id="country"
labelText="Country"
infoText="Select your country"
inputType="text"
:options="optionCountry"
@input-change="handleCountryChange"
v-model="country"
:isValid="store.step1.country_now.isValid"
:validationMessage="store.step1.country_now.validationMessage"
/>
</FieldContainer>
<FieldContainer>
<Textarea
id="street_address"
name="street_address"
labelText="Street Address"
labelColor="blue"
infoText="Street Address"
size="xl"
v-model="streetAddress"
:isValid="store.step1.street_address.isValid"
:validationMessage="store.step1.street_address.validationMessage"
/>
</FieldContainer>
<FieldContainer>
<Autocomp
name="city"
id="city"
labelText="City"
infoText="City"
inputType="text"
:options="optionCity"
@input-change="handleCityChange"
v-model="city"
:isValid="store.step1.city.isValid"
:validationMessage="store.step1.city.validationMessage"
/>
</FieldContainer>
<FieldContainer>
<Autocomp
name="governorate"
id="governorate"
labelText="Governorate"
infoText="Governorate"
inputType="text"
:options="optionGovernorate"
@input-change="handleGovernorateChange"
v-model="governorate"
:isValid="store.step1.governorate.isValid"
:validationMessage="store.step1.governorate.validationMessage"
/>
</FieldContainer>
<FieldContainer>
<StyledInput
labelText="Location Text"
:isMandatory="true"
infoText="Location Text"
inputType="text"
v-model="locationText"
:isValid="store.step1.location_text.isValid"
:validationMessage="store.step1.location_text.validationMessage"
name="location_text"
id="locationText"
/>
</FieldContainer>
<FieldContainer>
<StyledInput
labelText="Zip Code"
:isMandatory="true"
infoText="Zip Code"
inputType="text"
v-model="zipCode"
:isValid="store.step1.zip_code.isValid"
:validationMessage="store.step1.zip_code.validationMessage"
name="zip_code"
id="zipCode"
/>
</FieldContainer>
<FieldContainer>
<StyledInput
id="date_living_address"
name="date_living_address"
labelText="Date you started living at this address"
:isMandatory="true"
infoText="End date of your education."
inputType="date"
v-model="dateLivingAddress"
:isValid="store.step1.zip_code.isValid"
:validationMessage="store.step1.zip_code.validationMessage"
/>
</FieldContainer>
</div>
<FieldContainer>
<CheckBox
name="this_is_my_name_column"
id="this_is_my_name_column"
v-model="thisIsMyNameColumn"
>
I certify this is my current legal name, exactly as it is displayed on my government-issued identification document *
</CheckBox>
</FieldContainer>
<div class="lg:grid grid-ows-2 lg:gap-2">
<h1 class="text-lg font-medium text-black">Alias Name</h1>
<Info
text="Skip this section if you do not have any alias names.
Please provide:
Any other names appearing on government-issued identity documents where that name differs from your primary identity document; or
A prior legal name which can include your birth surname or any official change to a legal name and government identity documents were issued; or
A name that you use in an “official” capacity which can include any name under which you hold a professional qualification or that you use(d) to apply for any credit or may be recorded in any employee file at a current or past employer."
/>
</div>
<!-- إضافة قسم Alias Name -->
<div class="lg:grid grid-cols-1 lg:gap-2">
<h1 class="text-lg font-medium mb-1 mt-4 text-black">Alias Name</h1>
<Info text="Please provide your alias name." />
<!-- جدول فرعي لAlias Name -->
<div v-for="(alias, index) in aliasNames" :key="index" class="flex items-center mb-2">
<FieldContainer>
<StyledInput
labelText="Full Name"
inputType="text"
v-model="aliasNames[index].first_name"
:isValid="true"
:validationMessage="''"
name="first_name"
:id="aliasNames[index].first_name"
@input="updateAliasName(index, aliasNames[index].first_name)"
/>
</FieldContainer>
<FieldContainer>
<StyledInput
labelText="Middle Name"
inputType="text"
v-model="aliasNames[index].middle_name"
:isValid="true"
:validationMessage="''"
name="middle_name"
:id="`middle_name-${aliasNames[index]}`"
@input="updateAliasName(index, aliasNames[index].middle_name)"
/>
</FieldContainer>
<FieldContainer>
<StyledInput
labelText="Last Name"
inputType="text"
v-model="aliasNames[index].last_name"
:isValid="true"
:validationMessage="''"
name="last_name"
:id="`last_name-${aliasNames[index]}`"
@input="updateAliasName(index, aliasNames[index].last_name)"
/>
</FieldContainer>
<!-- زر حذف Alias Name -->
<Button @click="removeAliasName(index)" class="ml-2 bg-red-500 hover:bg-red-700 text-white font-bold py-2 px-4 rounded">
Remove
</Button>
</div>
<!-- زر إضافة Alias Name جديد -->
<Button @click="addAliasName" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
Add Alias Name
</Button>
</div>
<div class="lg:grid grid-ows-2 lg:gap-2">
<FieldContainer>
<StyledInput
labelText="Email"
:isMandatory="true"
infoText="Please enter your email address"
inputType="email"
name="email"
id="email"
v-model="email"
:isValid="store.step1.email.isValid"
:validationMessage="store.step1.email.validationMessage"
/>
</FieldContainer>
<Info
text=" Taakd may occasionally need to contact you for clarification of items on your Background Verification. We will never share or sell your email address"
/>
</div>
<!-- إضافة قسم أرقام الهواتف -->
<div class="lg:grid grid-cols-1 lg:gap-2">
<h1 class="text-lg font-medium mb-1 mt-4 text-black">Phone Numbers</h1>
<Info text="Please provide your phone numbers. You can add multiple phone numbers." />
<!-- جدول فرعي لأرقام الهواتف -->
<div v-for="(phone, index) in phoneNumbers" :key="index" class="flex items-center mb-2">
<FieldContainer>
<StyledInput
labelText="Phone"
inputType="text"
v-model="phoneNumbers[index].phone"
:isValid="true"
:validationMessage="''"
name="phone"
id="phone"
@input="updatePhoneNumber(index, phoneNumbers[index].phone)"
/>
</FieldContainer>
<!-- زر حذف رقم الهاتف -->
<Button @click="removePhoneNumber(index)" class="ml-2 bg-red-500 hover:bg-red-700 text-white font-bold py-2 px-4 rounded">
Remove
</Button>
</div>
<!-- زر إضافة رقم هاتف جديد -->
<Button @click="addPhoneNumber" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
Add Phone Number
</Button>
</div>
<div class="lg:grid grid-ows-2 lg:gap-2">
<h1 class="text-lg font-medium text-black">Identification</h1>
<Info
text=" Most public records are stored using your name and birth date, so providing this information allows us to accurately search these sources"
/>
</div>
<div class="lg:grid grid-cols-2 lg:gap-2">
<!-- Date of Birth -->
<FieldContainer>
<StyledInput
id="date_of_birth"
name="date_of_birth"
labelText="Date of Birth"
infoText="Start date of your education."
inputType="date"
v-model="dateOfBirth"
:isValid="store.step1.date_of_birth.isValid"
:validationMessage="store.step1.date_of_birth.validationMessage"
/>
</FieldContainer>
</div>
<div class="pt-5 flex w-full justify-center">
<Button level="other" @click="save" :disabled="loading" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
<span v-if="loading">جاري الحفظ...</span>
<span v-else>save -></span>
</Button>
</div>
</div>
</template>
<script setup lang="ts">
import { computed, onMounted, ref } from 'vue';
import { useVerificationRequestStore } from '../../stores/verificationRequest';
import CheckBox from '../../components/checkBox.vue';
import FieldContainer from '../../components/fieldContainer.vue';
import StyledInput from '../../components/styledInput.vue';
import SupportingText from '../../components/supportingText.vue';
import Info from './components/info.vue';
import { useToast } from 'vue-toastification';
import Button from '../../components/button.vue';
import Autocomp from '../../components/autocomp.vue';
import Textarea from '../../components/textarea.vue';
import { useLocation } from '../../stores/locations';
import { v4 as uuidv4 } from 'uuid'
const store = useVerificationRequestStore();
const toast = useToast();
const locations = useLocation();
const location = locations.getLocation();
// تعريف متغيرات التحميل
const loading = ref(false);
// خيارات Suffix
const suffixOptions = [
{ label: 'Jr.', value: 'Jr.' },
{ label: 'Sr.', value: 'Sr.' },
{ label: 'III', value: 'III' },
{ label: 'PhD', value: 'PhD' },
{ label: 'MD', value: 'MD' },
{ label: 'Esq.', value: 'Esq.' }
];
// تحميل البيانات عند تحميل الصفحة
// onMounted(async () => {
// loading.value = true;
// await store.loadStep1Fields();
// loading.value = false;
// });
// تعريف المتغيرات
const phoneNumbers = ref([{ phone: '' }]);
const aliasNames = ref([{ id:'',first_name: '', last_name: '', middle_name: '' }]);
const optionCountry = computed(() => {
if (location && location.data) {
return location.data
.filter((loc) => loc.location_type === 'Country')
.map((loc) => ({
label: loc.location_name,
value: loc.location_name,
}))
}
return [] // إرجاع مصفوفة فارغة إذا لم تتوفر البيانات
})
// فلترة المدن بناءً على الدولة
const optionCity = computed(() => {
if (location && location.data && country.value) {
return location.data
.filter(loc => loc.location_type === 'City' && loc.parent_location === country.value)
.map(loc => ({
label: loc.location_name,
value: loc.location_name
}));
}
return [];
});
// فلترة المحافظات بناءً على المدينة
const optionGovernorate = computed(() => {
if (location && location.data && city.value) {
return location.data
.filter(loc => loc.location_type === 'Governorate' && loc.parent_location === city.value)
.map(loc => ({
label: loc.location_name,
value: loc.location_name
}));
}
return [];
});
// تعريف computed properties لربط v-model مع مخزن Pinia
const employerName = computed({
get: () => store.step1.employer_name.value,
set: (val: string) => store.updateStep1('employer_name', { value: val }),
});
const firstName = computed({
get: () => store.step1.first_name.value,
set: (val: string) => store.updateStep1('first_name', { value: val }),
});
const lastName = computed({
get: () => store.step1.last_name.value,
set: (val: string) => store.updateStep1('last_name', { value: val }),
});
const dontMiddleName = computed({
get: () => store.step1.dont_middle_name.value,
set: (val: boolean) => store.updateStep1('dont_middle_name', { value: val }),
});
const middleName = computed({
get: () => store.step1.middle_name.value,
set: (val: string) => store.updateStep1('middle_name', { value: val }),
});
const thisIsMyNameColumn = computed({
get: () => store.step1.this_is_my_name_column.value,
set: (val: boolean) => store.updateStep1('this_is_my_name_column', { value: val }),
});
const suffix = computed({
get: () => store.step1.suffix.value,
set: (val: string) => store.updateStep1('suffix', { value: val }),
});
const country = computed({
get: () => store.step1.country_now.value,
set: (val: string) => store.updateStep1('country_now', { value: val }),
});
const governorate = computed({
get: () => store.step1.governorate.value,
set: (val: string) => store.updateStep1('governorate', { value: val }),
});
const city = computed({
get: () => store.step1.city.value,
set: (val: string) => store.updateStep1('city', { value: val }),
});
const locationText = computed({
get: () => store.step1.location_text.value,
set: (val: string) => store.updateStep1('location_text', { value: val }),
});
const streetAddress = computed({
get: () => store.step1.street_address.value,
set: (val: string) => store.updateStep1('street_address', { value: val }),
});
const zipCode = computed({
get: () => store.step1.zip_code.value,
set: (val: string) => store.updateStep1('zip_code', { value: val }),
});
const dateLivingAddress = computed({
get: () => store.step1.date_living_address.value,
set: (val: string) => store.updateStep1('date_living_address', { value: val }),
});
const email = computed({
get: () => store.step1.email.value,
set: (val: string) => store.updateStep1('email', { value: val }),
});
const dateOfBirth = computed({
get: () => store.step1.date_of_birth.value,
set: (val: string) => store.updateStep1('date_of_birth', { value: val }),
});
// const aliasName = computed({
// get: () => store.step1.alias_name.value,
// set: (val: string) => store.updateStep1('alias_name', { value: val })
// });
// const phone = computed({
// get: () => store.step1.phone.value,
// set: (val: string) => store.updateStep1('phone', { value: val })
// });
// معالجة تغيير اختيار الدولة
const handleCountryChange = (value) => {
// store.step1.country_now.value=value.value
store.updateStep1('country_now', { value: value.value });
};
const handleCityChange = (value) => {
// store.step1.city.value=value.value
store.updateStep1('city', { value: value.value });
};
const handleGovernorateChange = (value) => {
// store.step1.governorate.value=value.value
store.updateStep1('governorate', { value: value.value });
};
const handleSuffix = (value) => {
// store.step1.suffix.value=value.value
store.updateStep1('suffix', { value: value.value });
};
// دالة لإضافة رقم هاتف جديد
const addPhoneNumber = () => {
phoneNumbers.value.push({ phone: '' });
};
// دالة لحذف رقم هاتف
const removePhoneNumber = (index) => {
phoneNumbers.value.splice(index, 1);
};
// دالة لتحديث رقم هاتف
const updatePhoneNumber = (index, value) => {
store.updatePhoneNumber(index, value);
};
// دالة لإضافة Alias Name جديد
const addAliasName = () => {
aliasNames.value.push({ id:uuidv4(), first_name: '', last_name: '', middle_name: '' });
};
// دالة لحذف Alias Name
const removeAliasName = (index) => {
aliasNames.value.splice(index, 1);
};
// دالة لتحديث Alias Name
const updateAliasName = (index, value) => {
store.updateAliasName(index, value);
};
// دالة الحفظ
const save = async () => {
try {
console.log("*-*-*-*-*-*-**-*-",aliasNames)
console.log("*+*+*+*+*+*+*++*",phoneNumbers)
// store.updateStep1('phone', phoneNumbers.value);
// store.updateStep1('alias_name', aliasNames.value);
loading.value = true;
await store.saveStep1();
} catch (error) {
// معالجة الخطأ
} finally {
loading.value = false;
}
};
</script>
<style scoped>
/* أضف تنسيقات إضافية إذا لزم الأمر */
</style> ```
/**
* دالة تحميل الملف إلى الـ Doctype
* @param employmentId معرف التوظيف (uuid)
* @param file الملف الذي سيتم تحميله
*/
async uploadFile(employmentId: string, file: File) {
if (!this.documentName) {
throw new Error('Document name is not set.');
}
const formData = new FormData();
formData.append('filedata', file);
formData.append('doctype', 'Verification Instructions Request');
formData.append('docname', this.documentName);
formData.append('fieldname', 'file'); // تأكد من أن الحقل هو 'file' داخل الجدول الفرعي
formData.append('parentfield', 'employment_history'); // اسم جدول التوظيف الفرعي
formData.append('parenttype', 'Verification Instructions Request');
formData.append('employment_id', employmentId); // لربط الملف بسجل التوظيف المحدد
try {
const response = await axios.post(
'/api/method/taakd_app.taakd_app.doctype.verification_instructions_request.verification_instructions_request.upload_verification_file', // استبدل 'taakd_app' باسم تطبيقك الفعلي
formData,
{
headers: {
'Content-Type': 'multipart/form-data',
},
}
);
return response.data; // تأكد من المسار الصحيح للملف في الاستجابة
} catch (error) {
console.error('Error uploading file:', error);
throw error;
}
},
/**
* دوال تحميل الحقول لكل خطوة
*/
async loadHomeFields() {
try {
const request = createDocumentResource({
doctype: 'Verification Instructions Request',
name: this.documentName,
});
const data = await request.reload();
// تحديث الحقول في Home
this.updateHome('country', { value: data.country });
this.updateHome('mobile_number', { value: data.mobile_number });
this.updateHome('is_degree_or_diploma', { value: data.is_degree_or_diploma });
this.updateHome('from_time', { value: data.from_time });
this.updateHome('to_time', { value: data.to_time });
} catch (error) {
console.error("Error loading Home fields:", error);
const toast = useToast();
toast.error("حدث خطأ أثناء تحميل بيانات الحقول الرئيسية.");
}
},
async loadStep1Fields() {
try {
const request = createDocumentResource({
doctype: 'Verification Instructions Request',
name: this.documentName,
});
const data = await request.reload();
// تحديث الحقول في Step1
this.updateStep1('employer_name', { value: data.employer_name });
this.updateStep1('first_name', { value: data.first_name });
this.updateStep1('last_name', { value: data.last_name });
this.updateStep1('dont_middle_name', { value: data.dont_middle_name });
this.updateStep1('middle_name', { value: data.middle_name });
this.updateStep1('this_is_my_name_column', { value: data.this_is_my_name_column });
this.updateStep1('suffix', { value: data.suffix });
this.updateStep1('country_now', { value: data.country_now });
this.updateStep1('city', { value: data.city });
this.updateStep1('governorate', { value: data.governorate });
this.updateStep1('zip_code', { value: data.zip_code });
this.updateStep1('location_text', { value: data.location_text });
this.updateStep1('street_address', { value: data.street_address });
this.updateStep1('date_living_address', { value: data.date_living_address });
this.updateStep1('email', { value: data.email });
this.updateStep1('date_of_birth', { value: data.date_of_birth });
// تحميل الحقول الفرعية مثل alias_name و phone إذا كانت موجودة
if (data.alias_name && Array.isArray(data.alias_name)) {
this.step1.alias_name = data.alias_name;
}
if (data.phone && Array.isArray(data.phone)) {
this.step1.phone = data.phone;
}
// يمكنك إضافة المزيد من الحقول بناءً على احتياجاتك
this.validations = data.validations || this.validations; // تحديث التحققات إذا كانت موجودة
} catch (error) {
console.error("Error loading Step1 fields:", error);
const toast = useToast();
toast.error("حدث خطأ أثناء تحميل بيانات الخطوة الأولى.");
}
},
async loadStep2Fields() {
try {
const request = createDocumentResource({
doctype: 'Verification Instructions Request',
name: this.documentName,
});
const data = await request.reload();
// تحديث الحقول في Step2
this.step2.educationInformation = data.education_information;
} catch (error) {
console.error("Error loading Step2 fields:", error);
const toast = useToast();
toast.error("حدث خطأ أثناء تحميل بيانات الخطوة الثانية.");
}
},
async loadStep3Fields() {
try {
const request = createDocumentResource({
doctype: 'Verification Instructions Request',
name: this.documentName,
});
const data = await request.reload();
// تحديث الحقول في Step3
this.step3.employment_history = data.employment_history;
} catch (error) {
console.error("Error loading Step3 fields:", error);
const toast = useToast();
toast.error("حدث خطأ أثناء تحميل بيانات الخطوة الثالثة.");
}
},
async loadStep4Fields() {
try {
const request = createDocumentResource({
doctype: 'Verification Instructions Request',
name: this.documentName,
});
const data = await request.reload();
// تحديث الحقول في Step4
this.step4.professional_qualification = data.professional_qualification;
} catch (error) {
console.error("Error loading Step4 fields:", error);
const toast = useToast();
toast.error("حدث خطأ أثناء تحميل بيانات الخطوة الرابعة.");
}
},
async loadStep6Fields() {
try {
const request = createDocumentResource({
doctype: 'Verification Instructions Request',
name:this.documentName,
});
const data = await request.reload(); // تأكد من كيفية جلب البيانات حسب مكتبة frappe-ui
// تحديث الحقول في Step6
this.updateStep6('other_languages', { value: data.other_languages });
this.updateStep6('electronic_signature', { value: data.electronic_signature });
this.updateStep6('full_name', { value: data.full_name });
this.updateStep6('email_address', { value: data.email_address });
this.updateStep6('i_agree_to_the_electronic_signature', { value: data.i_agree_to_the_electronic_signature });
this.updateStep6('acknowledge_electronic_signature', { value: data.acknowledge_electronic_signature });
this.updateStep6('i_acknowledge_the_above', { value: data.i_acknowledge_the_above });
} catch (error) {
console.error("Error loading Step6 fields:", error);
const toast = useToast();
toast.error("حدث خطأ أثناء تحميل بيانات الخطوة السادسة.");
}
},
},
}); ```
import { defineStore } from 'pinia';
import { useToast } from 'vue-toastification'; // تأكد من وجود مكتبة التوست
export const useVerificationRequestStore = defineStore('verificationRequest', {
state: () => ({
step1: {
employer_name: {},
first_name: {},
last_name: {},
dont_middle_name: {},
middle_name: {},
this_is_my_name_column: {},
suffix: {},
country_now: {},
city: {},
governorate: {},
zip_code: {},
location_text: {},
street_address: {},
date_living_address: {},
email: {},
date_of_birth: {},
phone: [], // إضافة هنا
alias_name: [] // إضافة هنا
},
validations: {},
}),
actions: {
// الدوال الأخرى...
async loadStep1Fields() {
// ...الكود السابق...
// تحميل الحقول الفرعية مثل alias_name و phone إذا كانت موجودة
if (data.alias_name && Array.isArray(data.alias_name)) {
this.step1.alias_name = data.alias_name.map(item => ({
first_name: item.first_name,
middle_name: item.middle_name,
last_name: item.last_name
}));
}
if (data.phone && Array.isArray(data.phone)) {
this.step1.phone = data.phone.map(item => ({
phone: item.phone
}));
}
// ...الكود السابق...
},
updatePhoneNumber(index: number, value: string) {
if (this.step1.phone[index]) {
this.step1.phone[index].phone = value; // تحديث الرقم
}
},
updateAliasName(index: number, value: { first_name: string; middle_name?: string; last_name: string; }) {
if (this.step1.alias_name[index]) {
this.step1.alias_name[index] = value; // تحديث الاسم المستعار
}
},
async saveStep1() {
// احصل على البيانات الحالية
const payload = {
...this.step1,
};
try {
// قم بالمزامنة مع API هنا
const response = await axios.post('/api/saveStep1', payload); // تأكد من تعديل هذا المسار
return response.data;
} catch (error) {
console.error('خطأ في حفظ البيانات:', error);
const toast = useToast();
toast.error("حدث خطأ أثناء حفظ البيانات.");
throw error; // يمكن إعادة الخطأ للمعالجة لاحقاً
}
}
// ...الدوال الأخرى...
}
});
ملاحظات على التعديلات:
التأكد من تهيئة الـ phone و alias_name : تم التأكد من أن كل من phone و alias_name تم تهيئتهما كأقسام من حالة step1.
معالجة القيم : تم استخدام map لتحويل البيانات المحملة إلى الشكل المطلوب وتخزينها.
الدوال الجديدة : تم إضافة دوال updatePhoneNumber و updateAliasName لضمان إمكانية تحديث بيانات الهواتف والأسماء المستعارة بشكل صحيح.
دالة saveStep1 : تم تعديل هذه الدالة لتشمل البيانات من الحقول الفرعية أثناء طلب الحفظ.
الخطوة التالية: الآن، إذا قمت بإجراء التعديلات الضرورية في step1.vue (التي قدمتها سابقًا)، يمكننا أن نكون مستعدين لحفظ وتحميل البيانات الخاصة بك بنجاح. إذا كان لديك أي استفسارات أو مواد أخرى تحتاج مراجعتها، فلا تتردد في إخباري!
// واجهة لحقل النموذج
export interface FormField<T = any> {
value: T;
isValid: boolean;
validationMessage: string;
touched?: boolean;
}
// واجهات البيانات لكل خطوة
export interface HomeData {
country: FormField<string>;
mobile_number: FormField<string>;
is_degree_or_diploma: FormField<boolean>;
from_time: FormField<string>;
to_time: FormField<string>;
}
export interface PhoneNumber {
id: string;
phone: string;
}
export interface AliasName {
id: string;
first_name: string;
last_name: string;
middle_name: string;
}
export interface Step1Data {
employer_name: FormField<string>;
first_name: FormField<string>;
last_name: FormField<string>;
dont_middle_name: FormField<boolean>;
middle_name: FormField<string>;
this_is_my_name_column: FormField<boolean>;
suffix: FormField<string>;
alias_name: AliasName[];
country_now: FormField<string>;
city: FormField<string>;
governorate: FormField<string>;
zip_code: FormField<string>;
location_text: FormField<string>;
street_address: FormField<string>;
date_living_address: FormField<string>;
phone: PhoneNumber[];
email: FormField<string>;
date_of_birth: FormField<string>;
}
export interface EducationInformation {
id: string;
name_of_school_or_college_university: string;
country: string;
city: string;
governorate: string;
location_text: string;
from_date: string;
to_date: string;
field_of_study_or_major: string;
phone: string;
ext: string;
diploma: string;
another_name: string;
}
export interface EmploymentHistory {
id: string;
company: string;
name_of_your_employer: string;
contact_the_employer: boolean;
issuing_salary: boolean;
country: string;
city: string;
governorate: string;
location_text: string;
continuous: boolean;
activity_has_stopped: boolean;
from_date: string;
end_date: string;
phone: string;
ext: string;
official_job_title_held_currently: string;
type_of_employment: string;
the_company_has_different_names: boolean;
different_company_names: string;
you_have_a_nicknamecx: boolean;
nickname: string;
file: File | string | null; // دعم كائن File أو رابط الملف (string)
}
export interface ProfessionalQualification {
id: string;
awarding_body: string;
license_or_certificate_number: string;
issuing_country: string;
date_awarded: string;
expiration_date?: string; // اختياري
award_name_description: string;
is_an_expiration_date: boolean;
your_name_varies: boolean;
}
export interface Step2Data {
educationInformation: EducationInformation[];
}
export interface Step3Data {
employment_history: EmploymentHistory[];
}
export interface Step4Data {
professional_qualification: ProfessionalQualification[];
}
export interface Step6Data {
other_languages: FormField<string[]>; // تصحيح النوع إلى string[]
electronic_signature: FormField<string>;
full_name: FormField<string>;
email_address: FormField<string>;
i_agree_to_the_electronic_signature: FormField<boolean>;
i_acknowledge_the_above: FormField<boolean>; // إضافة هذا الحقل
}
export interface ValidationResult {
[key: string]: {
isValid: boolean;
validationMessage?: string;
};
}
// واجهة RequestData: تمثل مجموعة كافة البيانات من الخطوات (للإرسال إلى الخادم)
export interface RequestData {
name: string;
user_id: string;
// Home
country: string;
mobile_number: string;
is_degree_or_diploma: boolean;
from_time: string;
to_time: string;
// Step1
employer_name: string;
first_name: string;
last_name: string;
dont_middle_name: boolean;
middle_name: string;
this_is_my_name_column: boolean;
suffix: string;
alias_name: AliasName[];
city: string;
country_now: string;
governorate: string;
zip_code: string;
location_text: string;
street_address: string;
date_living_address: string;
phone: PhoneNumber[];
email: string;
date_of_birth: string;
// Step2
education_information: EducationInformation[];
// Step3
employment_history: EmploymentHistory[];
// Step4
professional_qualification: ProfessionalQualification[];
// Step6
other_languages: string[];
electronic_signature: string;
full_name: string;
email_address: string;
i_agree_to_the_electronic_signature: boolean;
i_acknowledge_the_above: boolean; // إضافة هذا الحقل
}
// واجهة UpdateFields: لتمثيل الحقول المحدثة
export interface UpdateFields {
[key: string]: any;
}
export type FormData = {
home: HomeData &
Step1Data &
Step2Data &
Step3Data &
Step4Data &
Step6Data;
}; ```
<template>
<div class="pt-3 container">
<h1 class="text-3xl font-bold mb-3 text-black">Personal Information</h1>
<ul>
<li>All fields marked with an asterisk ( * ) are required.</li>
<li>Providing your information as completely and accurately as possible will help speed up the completion of your Background Verification</li>
</ul>
<div class="lg:grid grid-rows-2 lg:gap-2">
<h1 class="text-lg font-medium mb-1 mt-4 text-black">Name</h1>
<Info
text="Please provide your name exactly as it appears on your current government-issued identification document such as your Passport, Driver’s License or National Identification Document"
/>
</div>
<!-- باقي النموذج هنا ... -->
<!-- إضافة قسم Alias Name -->
<div class="lg:grid grid-cols-1 lg:gap-2">
<h1 class="text-lg font-medium mb-1 mt-4 text-black">Alias Name</h1>
<Info text="Please provide your alias name." />
<!-- جدول فرعي لAlias Name -->
<div v-for="(alias, index) in aliasNames" :key="alias.id" class="flex items-center mb-2">
<FieldContainer>
<StyledInput
labelText="Full Name"
inputType="text"
v-model="aliasNames[index].first_name"
:isValid="true"
:validationMessage="''"
name="first_name"
:id="aliasNames[index].id"
@input="updateAliasName(index, aliasNames[index])"
/>
</FieldContainer>
<FieldContainer>
<StyledInput
labelText="Middle Name"
inputType="text"
v-model="aliasNames[index].middle_name"
:isValid="true"
:validationMessage="''"
name="middle_name"
:id="aliasNames[index].id"
@input="updateAliasName(index, aliasNames[index])"
/>
</FieldContainer>
<FieldContainer>
<StyledInput
labelText="Last Name"
inputType="text"
v-model="aliasNames[index].last_name"
:isValid="true"
:validationMessage="''"
name="last_name"
:id="aliasNames[index].id"
@input="updateAliasName(index, aliasNames[index])"
/>
</FieldContainer>
<!-- زر حذف Alias Name -->
<Button @click="removeAliasName(index)" class="ml-2 bg-red-500 hover:bg-red-700 text-white font-bold py-2 px-4 rounded">
Remove
</Button>
</div>
<!-- زر إضافة Alias Name جديد -->
<Button @click="addAliasName" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
Add Alias Name
</Button>
</div>
<!-- إضافة قسم أرقام الهواتف -->
<div class="lg:grid grid-cols-1 lg:gap-2">
<h1 class="text-lg font-medium mb-1 mt-4 text-black">Phone Numbers</h1>
<Info text="Please provide your phone numbers. You can add multiple phone numbers." />
<!-- جدول فرعي لأرقام الهواتف -->
<div v-for="(phone, index) in phoneNumbers" :key="index" class="flex items-center mb-2">
<FieldContainer>
<StyledInput
labelText="Phone"
inputType="text"
v-model="phoneNumbers[index].phone"
:isValid="true"
:validationMessage="''"
name="phone"
id="phone"
@input="updatePhoneNumber(index, phoneNumbers[index])"
/>
</FieldContainer>
<!-- زر حذف رقم الهاتف -->
<Button @click="removePhoneNumber(index)" class="ml-2 bg-red-500 hover:bg-red-700 text-white font-bold py-2 px-4 rounded">
Remove
</Button>
</div>
<!-- زر إضافة رقم هاتف جديد -->
<Button @click="addPhoneNumber" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
Add Phone Number
</Button>
</div>
<div class="pt-5 flex w-full justify-center">
<Button level="other" @click="save" :disabled="loading" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
<span v-if="loading">جاري الحفظ...</span>
<span v-else>save -></span>
</Button>
</div>
</div>
</template>
<script setup lang="ts">
import { computed, ref } from 'vue';
import { useVerificationRequestStore } from '../../stores/verificationRequest';
import CheckBox from '../../components/checkBox.vue';
import FieldContainer from '../../components/fieldContainer.vue';
import StyledInput from '../../components/styledInput.vue';
import Info from './components/info.vue';
import Button from '../../components/button.vue';
import { v4 as uuidv4 } from 'uuid';
const store = useVerificationRequestStore();
const loading = ref(false);
const phoneNumbers = ref([{ id: uuidv4(), phone: '' }]);
const aliasNames = ref([{ id: uuidv4(), first_name: '', last_name: '', middle_name: '' }]);
// دالة لإضافة رقم هاتف جديد
const addPhoneNumber = () => {
phoneNumbers.value.push({ id: uuidv4(), phone: '' });
};
// دالة لحذف رقم هاتف
const removePhoneNumber = (index) => {
phoneNumbers.value.splice(index, 1);
};
// دالة لتحديث رقم هاتف
const updatePhoneNumber = (index, value) => {
store.updatePhoneNumber(index, value.phone);
};
// دالة لإضافة Alias Name جديد
const addAliasName = () => {
aliasNames.value.push({ id: uuidv4(), first_name: '', last_name: '', middle_name: '' });
};
// دالة لحذف Alias Name
const removeAliasName = (index) => {
aliasNames.value.splice(index, 1);
};
// دالة لتحديث Alias Name
const updateAliasName = (index, value) => {
store.updateAliasName(index, value);
};
// دالة الحفظ
const save = async () => {
try {
loading.value = true;
await store.saveStep1();
} catch (error) {
// معالجة الخطأ
} finally {
loading.value = false;
}
};
</script>
<style scoped>
/* أضف تنسيقات إضافية إذا لزم الأمر */
</style>
2. ملف verificationRequest.ts typescript Copy code
import { defineStore } from 'pinia';
import { useToast } from 'vue-toastification';
import axios from 'axios';
export const useVerificationRequestStore = defineStore('verificationRequest', {
state: () => ({
step1: {
employer_name: {},
first_name: {},
last_name: {},
dont_middle_name: {},
middle_name: {},
this_is_my_name_column: {},
suffix: {},
alias_name: [], // قائمة من الأسماء المستعارة
country_now: {},
city: {},
governorate: {},
zip_code: {},
location_text: {},
street_address: {},
date_living_address: {},
phone: [], // قائمة من أرقام الهواتف
email: {},
date_of_birth: {},
},
validations: {},
}),
actions: {
async loadStep1Fields() {
try {
const response = await axios.get(`/api/verificationInstructionsRequest/${this.documentName}`);
const data = response.data;
// تحديث الحقول في Step1
this.updateStep1('employer_name', { value: data.employer_name });
this.updateStep1('first_name', { value: data.first_name });
this.updateStep1('last_name', { value: data.last_name });
this.updateStep1('dont_middle_name', { value: data.dont_middle_name });
this.updateStep1('middle_name', { value: data.middle_name });
this.updateStep1('this_is_my_name_column', { value: data.this_is_my_name_column });
this.updateStep1('suffix', { value: data.suffix });
this.updateStep1('country_now', { value: data.country_now });
this.updateStep1('city', { value: data.city });
this.updateStep1('governorate', { value: data.governorate });
this.updateStep1('zip_code', { value: data.zip_code });
this.updateStep1('location_text', { value: data.location_text });
this.updateStep1('street_address', { value: data.street_address });
this.updateStep1('date_living_address', { value: data.date_living_address });
this.updateStep1('email', { value: data.email });
this.updateStep1('date_of_birth', { value: data.date_of_birth });
// تحميل الحقول الفرعية مثل alias_name و phone إذا كانت موجودة
if (data.alias_name && Array.isArray(data.alias_name)) {
this.step1.alias_name = data.alias_name;
}
if (data.phone && Array.isArray(data.phone)) {
this.step1.phone = data.phone;
}
} catch (error) {
const toast = useToast();
toast.error("حدث خطأ أثناء تحميل بيانات الخطوة الأولى.");
}
},
updatePhoneNumber(index: number, value: string) {
if (this.step1.phone[index]) {
this.step1.phone[index].phone = value; // تحديث الرقم
}
},
updateAliasName(index: number, value: { first_name: string; middle_name?: string; last_name: string; }) {
if (this.step1.alias_name[index]) {
this.step1.alias_name[index] = value; // تحديث الاسم المستعار
}
},
async saveStep1() {
const payload = {
...this.step1,
};
try {
await axios.post('/api/saveVerificationRequest', payload); // تأكد من تعديل هذا المسار
} catch (error) {
const toast = useToast();
toast.error("حدث خطأ أثناء حفظ البيانات.");
throw error;
}
}
}
});
3. ملف types.ts typescript Copy code
// واجهة لحقل النموذج
export interface FormField<T = any> {
value: T;
isValid: boolean;
validationMessage: string;
touched?: boolean;
}
export interface PhoneNumber {
id: string;
phone: string;
}
export interface AliasName {
id: string;
first_name: string;
last_name: string;
middle_name: string;
}
export interface Step1Data {
employer_name: FormField<string>;
first_name: FormField<string>;
last_name: FormField<string>;
dont_middle_name: FormField<boolean>;
middle_name: FormField<string>;
this_is_my_name_column: FormField<boolean>;
suffix: FormField<string>;
alias_name: AliasName[];
country_now: FormField<string>;
city: FormField<string>;
governorate: FormField<string>;
zip_code: FormField<string>;
location_text: FormField<string>;
street_address: FormField<string>;
date_living_address: FormField<string>;
phone: PhoneNumber[];
email: FormField<string>;
date_of_birth: FormField<string>;
}
// واجهة RequestData: تمثل مجموعة كافة البيانات من الخطوات (للإرسال إلى الخادم)
export interface RequestData {
name: string;
user_id: string;
country: string;
mobile_number: string;
is_degree_or_diploma: boolean;
from_time: string;
to_time: string;
employer_name: string;
first_name: string;
last_name: string;
dont_middle_name: boolean;
middle_name: string;
this_is_my_name_column: boolean;
suffix: string;
alias_name: AliasName[];
city: string;
country_now: string;
governorate: string;
zip_code: string;
location_text: string;
street_address: string;
date_living_address: string;
phone: PhoneNumber[];
email: string;
date_of_birth: string;
}
// واجهة UpdateFields: لتمثيل الحقول المحدثة
export interface UpdateFields {
[key: string]: any;
}
الخلاصة:
الكود المحدث يغطي الجوانب المتعلقة بإدارة أرقام الهواتف وأسماء المستعارة بشكل فعال.
جميع الملفات مرتبطة بطريقة تضمن تدفق البيانات بسلاسة من الواجهة إلى التخزين.
يمكن توسيع الوظائف بسهولة عند الحاجة وفقًا للمتطلبات المستقبلية.
إذا كان لديك أي أسئلة أخرى أو تحتاج إلى المزيد من التعديلات، فلا تتردد في التواصل!
<!-- /pages/stepsSections/step1.vue -->
<template>
<div class="pt-3 container">
<h1 class="text-3xl font-bold mb-3 text-black">Personal Information</h1>
<ul>
<li>All fields marked with an asterisk ( * ) are required.</li>
<li>Providing your information as completely and accurately as possible will help speed up the completion of your Background Verification</li>
</ul>
<div class="lg:grid grid-rows-2 lg:gap-2">
<h1 class="text-lg font-medium mb-1 mt-4 text-black">Name</h1>
<Info
text="Please provide your name exactly as it appears on your current government-issued identification document such as your Passport, Driver’s License or National Identification Document"
/>
</div>
<div class="lg:grid grid-cols-2 lg:gap-2">
<FieldContainer>
<StyledInput
labelText="Employer Name"
:isMandatory="true"
infoText="Employer Name"
inputType="text"
v-model="employerName"
:isValid="store.step1.employer_name.isValid"
:validationMessage="store.step1.employer_name.validationMessage"
name="employer_name"
id="EmployerName"
/>
<SupportingText>Supporting text</SupportingText>
</FieldContainer>
<FieldContainer>
<StyledInput
labelText="First Name"
:isMandatory="true"
infoText="First Name"
inputType="text"
v-model="firstName"
:isValid="store.step1.first_name.isValid"
:validationMessage="store.step1.first_name.validationMessage"
name="first_name"
id="firstName"
/>
</FieldContainer>
</div>
<FieldContainer>
<CheckBox
name="dont_middle_name"
id="dont_middle_name"
v-model="dontMiddleName"
>
I certify that I do not have a Middle Name on my official identification document
</CheckBox>
</FieldContainer>
<div class="lg:grid grid-cols-2 lg:gap-2">
<FieldContainer v-if="!dontMiddleName">
<StyledInput
labelText="Middle Name"
inputType="text"
v-model="middleName"
:isValid="store.step1.middle_name.isValid"
:validationMessage="store.step1.middle_name.validationMessage"
name="middle_name"
id="MiddleName"
/>
</FieldContainer>
</div>
<div class="lg:grid grid-cols-2 lg:gap-2">
<FieldContainer>
<StyledInput
labelText="Last Name"
:isMandatory="true"
infoText="Last Name"
inputType="text"
v-model="lastName"
:isValid="store.step1.last_name.isValid"
:validationMessage="store.step1.last_name.validationMessage"
name="last_name"
id="lastName"
/>
</FieldContainer>
<FieldContainer>
<Autocomp
id="suffix"
name="suffix"
labelText="Suffix"
infoText="Select your suffix"
inputType="text"
:options="suffixOptions"
@input-change="handleSuffix"
v-model="suffix"
:isValid="store.step1.suffix.isValid"
:validationMessage="store.step1.suffix.validationMessage"
/>
</FieldContainer>
</div>
<div class="lg:grid grid-cols-2 lg:gap-2">
<FieldContainer>
<Autocomp
name="country_now"
id="country"
labelText="Country"
infoText="Select your country"
inputType="text"
:options="optionCountry"
@input-change="handleCountryChange"
v-model="country"
:isValid="store.step1.country_now.isValid"
:validationMessage="store.step1.country_now.validationMessage"
/>
</FieldContainer>
<FieldContainer>
<Textarea
id="street_address"
name="street_address"
labelText="Street Address"
labelColor="blue"
infoText="Street Address"
size="xl"
v-model="streetAddress"
:isValid="store.step1.street_address.isValid"
:validationMessage="store.step1.street_address.validationMessage"
/>
</FieldContainer>
<FieldContainer>
<Autocomp
name="city"
id="city"
labelText="City"
infoText="City"
inputType="text"
:options="optionCity"
@input-change="handleCityChange"
v-model="city"
:isValid="store.step1.city.isValid"
:validationMessage="store.step1.city.validationMessage"
/>
</FieldContainer>
<FieldContainer>
<Autocomp
name="governorate"
id="governorate"
labelText="Governorate"
infoText="Governorate"
inputType="text"
:options="optionGovernorate"
@input-change="handleGovernorateChange"
v-model="governorate"
:isValid="store.step1.governorate.isValid"
:validationMessage="store.step1.governorate.validationMessage"
/>
</FieldContainer>
<FieldContainer>
<StyledInput
labelText="Location Text"
:isMandatory="true"
infoText="Location Text"
inputType="text"
v-model="locationText"
:isValid="store.step1.location_text.isValid"
:validationMessage="store.step1.location_text.validationMessage"
name="location_text"
id="locationText"
/>
</FieldContainer>
<FieldContainer>
<StyledInput
labelText="Zip Code"
:isMandatory="true"
infoText="Zip Code"
inputType="text"
v-model="zipCode"
:isValid="store.step1.zip_code.isValid"
:validationMessage="store.step1.zip_code.validationMessage"
name="zip_code"
id="zipCode"
/>
</FieldContainer>
<FieldContainer>
<StyledInput
id="date_living_address"
name="date_living_address"
labelText="Date you started living at this address"
:isMandatory="true"
infoText="End date of your education."
inputType="date"
v-model="dateLivingAddress"
:isValid="store.step1.zip_code.isValid"
:validationMessage="store.step1.zip_code.validationMessage"
/>
</FieldContainer>
</div>
<FieldContainer>
<CheckBox
name="this_is_my_name_column"
id="this_is_my_name_column"
v-model="thisIsMyNameColumn"
>
I certify this is my current legal name, exactly as it is displayed on my government-issued identification document *
</CheckBox>
</FieldContainer>
<div class="lg:grid grid-ows-2 lg:gap-2">
<h1 class="text-lg font-medium text-black">Alias Name</h1>
<Info
text="Skip this section if you do not have any alias names.
Please provide:
Any other names appearing on government-issued identity documents where that name differs from your primary identity document; or
A prior legal name which can include your birth surname or any official change to a legal name and government identity documents were issued; or
A name that you use in an “official” capacity which can include any name under which you hold a professional qualification or that you use(d) to apply for any credit or may be recorded in any employee file at a current or past employer."
/>
</div>
<!-- إضافة قسم Alias Name -->
<div class="lg:grid grid-cols-1 lg:gap-2">
<h1 class="text-lg font-medium mb-1 mt-4 text-black">Alias Name</h1>
<Info text="Please provide your alias name." />
<!-- جدول فرعي لAlias Name -->
<div v-for="(alias, index) in aliasNames" :key="index" class="flex items-center mb-2">
<FieldContainer>
<StyledInput
labelText="Full Name"
inputType="text"
v-model="aliasNames[index].first_name"
:isValid="true"
:validationMessage="''"
name="first_name"
:id="aliasNames[index].first_name"
@input="updateAliasName(index, aliasNames[index].first_name)"
/>
</FieldContainer>
<FieldContainer>
<StyledInput
labelText="Middle Name"
inputType="text"
v-model="aliasNames[index].middle_name"
:isValid="true"
:validationMessage="''"
name="middle_name"
:id="`middle_name-${aliasNames[index]}`"
@input="updateAliasName(index, aliasNames[index].middle_name)"
/>
</FieldContainer>
<FieldContainer>
<StyledInput
labelText="Last Name"
inputType="text"
v-model="aliasNames[index].last_name"
:isValid="true"
:validationMessage="''"
name="last_name"
:id="`last_name-${aliasNames[index]}`"
@input="updateAliasName(index, aliasNames[index].last_name)"
/>
</FieldContainer>
<!-- زر حذف Alias Name -->
<Button @click="removeAliasName(index)" class="ml-2 bg-red-500 hover:bg-red-700 text-white font-bold py-2 px-4 rounded">
Remove
</Button>
</div>
<!-- زر إضافة Alias Name جديد -->
<Button @click="addAliasName" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
Add Alias Name
</Button>
</div>
<div class="lg:grid grid-ows-2 lg:gap-2">
<FieldContainer>
<StyledInput
labelText="Email"
:isMandatory="true"
infoText="Please enter your email address"
inputType="email"
name="email"
id="email"
v-model="email"
:isValid="store.step1.email.isValid"
:validationMessage="store.step1.email.validationMessage"
/>
</FieldContainer>
<Info
text=" Taakd may occasionally need to contact you for clarification of items on your Background Verification. We will never share or sell your email address"
/>
</div>
<!-- إضافة قسم أرقام الهواتف -->
<div class="lg:grid grid-cols-1 lg:gap-2">
<h1 class="text-lg font-medium mb-1 mt-4 text-black">Phone Numbers</h1>
<Info text="Please provide your phone numbers. You can add multiple phone numbers." />
<!-- جدول فرعي لأرقام الهواتف -->
<div v-for="(phone, index) in phoneNumbers" :key="index" class="flex items-center mb-2">
<FieldContainer>
<StyledInput
labelText="Phone"
inputType="text"
v-model="phoneNumbers[index].phone"
:isValid="true"
:validationMessage="''"
name="phone"
id="phone"
@input="updatePhoneNumber(index, phoneNumbers[index].phone)"
/>
</FieldContainer>
<!-- زر حذف رقم الهاتف -->
<Button @click="removePhoneNumber(index)" class="ml-2 bg-red-500 hover:bg-red-700 text-white font-bold py-2 px-4 rounded">
Remove
</Button>
</div>
<!-- زر إضافة رقم هاتف جديد -->
<Button @click="addPhoneNumber" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
Add Phone Number
</Button>
</div>
<div class="lg:grid grid-ows-2 lg:gap-2">
<h1 class="text-lg font-medium text-black">Identification</h1>
<Info
text=" Most public records are stored using your name and birth date, so providing this information allows us to accurately search these sources"
/>
</div>
<div class="lg:grid grid-cols-2 lg:gap-2">
<!-- Date of Birth -->
<FieldContainer>
<StyledInput
id="date_of_birth"
name="date_of_birth"
labelText="Date of Birth"
infoText="Start date of your education."
inputType="date"
v-model="dateOfBirth"
:isValid="store.step1.date_of_birth.isValid"
:validationMessage="store.step1.date_of_birth.validationMessage"
/>
</FieldContainer>
</div>
<div class="pt-5 flex w-full justify-center">
<Button level="other" @click="save" :disabled="loading" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
<span v-if="loading">جاري الحفظ...</span>
<span v-else>save -></span>
</Button>
</div>
</div>
</template>
<script setup lang="ts">
import { computed, onMounted, ref } from 'vue';
import { useVerificationRequestStore } from '../../stores/verificationRequest';
import CheckBox from '../../components/checkBox.vue';
import FieldContainer from '../../components/fieldContainer.vue';
import StyledInput from '../../components/styledInput.vue';
import SupportingText from '../../components/supportingText.vue';
import Info from './components/info.vue';
import { useToast } from 'vue-toastification';
import Button from '../../components/button.vue';
import Autocomp from '../../components/autocomp.vue';
import Textarea from '../../components/textarea.vue';
import { useLocation } from '../../stores/locations';
import { v4 as uuidv4 } from 'uuid'
const store = useVerificationRequestStore();
const toast = useToast();
const locations = useLocation();
const location = locations.getLocation();
// تعريف متغيرات التحميل
const loading = ref(false);
// خيارات Suffix
const suffixOptions = [
{ label: 'Jr.', value: 'Jr.' },
{ label: 'Sr.', value: 'Sr.' },
{ label: 'III', value: 'III' },
{ label: 'PhD', value: 'PhD' },
{ label: 'MD', value: 'MD' },
{ label: 'Esq.', value: 'Esq.' }
];
// تحميل البيانات عند تحميل الصفحة
// onMounted(async () => {
// loading.value = true;
// await store.loadStep1Fields();
// loading.value = false;
// });
// تعريف المتغيرات
const phoneNumbers = ref([{ phone: '' }]);
const aliasNames = ref([{ id:'',first_name: '', last_name: '', middle_name: '' }]);
const optionCountry = computed(() => {
if (location && location.data) {
return location.data
.filter((loc) => loc.location_type === 'Country')
.map((loc) => ({
label: loc.location_name,
value: loc.location_name,
}))
}
return [] // إرجاع مصفوفة فارغة إذا لم تتوفر البيانات
})
// فلترة المدن بناءً على الدولة
const optionCity = computed(() => {
if (location && location.data && country.value) {
return location.data
.filter(loc => loc.location_type === 'City' && loc.parent_location === country.value)
.map(loc => ({
label: loc.location_name,
value: loc.location_name
}));
}
return [];
});
// فلترة المحافظات بناءً على المدينة
const optionGovernorate = computed(() => {
if (location && location.data && city.value) {
return location.data
.filter(loc => loc.location_type === 'Governorate' && loc.parent_location === city.value)
.map(loc => ({
label: loc.location_name,
value: loc.location_name
}));
}
return [];
});
// تعريف computed properties لربط v-model مع مخزن Pinia
const employerName = computed({
get: () => store.step1.employer_name.value,
set: (val: string) => store.updateStep1('employer_name', { value: val }),
});
const firstName = computed({
get: () => store.step1.first_name.value,
set: (val: string) => store.updateStep1('first_name', { value: val }),
});
const lastName = computed({
get: () => store.step1.last_name.value,
set: (val: string) => store.updateStep1('last_name', { value: val }),
});
const dontMiddleName = computed({
get: () => store.step1.dont_middle_name.value,
set: (val: boolean) => store.updateStep1('dont_middle_name', { value: val }),
});
const middleName = computed({
get: () => store.step1.middle_name.value,
set: (val: string) => store.updateStep1('middle_name', { value: val }),
});
const thisIsMyNameColumn = computed({
get: () => store.step1.this_is_my_name_column.value,
set: (val: boolean) => store.updateStep1('this_is_my_name_column', { value: val }),
});
const suffix = computed({
get: () => store.step1.suffix.value,
set: (val: string) => store.updateStep1('suffix', { value: val }),
});
const country = computed({
get: () => store.step1.country_now.value,
set: (val: string) => store.updateStep1('country_now', { value: val }),
});
const governorate = computed({
get: () => store.step1.governorate.value,
set: (val: string) => store.updateStep1('governorate', { value: val }),
});
const city = computed({
get: () => store.step1.city.value,
set: (val: string) => store.updateStep1('city', { value: val }),
});
const locationText = computed({
get: () => store.step1.location_text.value,
set: (val: string) => store.updateStep1('location_text', { value: val }),
});
const streetAddress = computed({
get: () => store.step1.street_address.value,
set: (val: string) => store.updateStep1('street_address', { value: val }),
});
const zipCode = computed({
get: () => store.step1.zip_code.value,
set: (val: string) => store.updateStep1('zip_code', { value: val }),
});
const dateLivingAddress = computed({
get: () => store.step1.date_living_address.value,
set: (val: string) => store.updateStep1('date_living_address', { value: val }),
});
const email = computed({
get: () => store.step1.email.value,
set: (val: string) => store.updateStep1('email', { value: val }),
});
const dateOfBirth = computed({
get: () => store.step1.date_of_birth.value,
set: (val: string) => store.updateStep1('date_of_birth', { value: val }),
});
// const aliasName = computed({
// get: () => store.step1.alias_name.value,
// set: (val: string) => store.updateStep1('alias_name', { value: val })
// });
// const phone = computed({
// get: () => store.step1.phone.value,
// set: (val: string) => store.updateStep1('phone', { value: val })
// });
// معالجة تغيير اختيار الدولة
const handleCountryChange = (value) => {
// store.step1.country_now.value=value.value
store.updateStep1('country_now', { value: value.value });
};
const handleCityChange = (value) => {
// store.step1.city.value=value.value
store.updateStep1('city', { value: value.value });
};
const handleGovernorateChange = (value) => {
// store.step1.governorate.value=value.value
store.updateStep1('governorate', { value: value.value });
};
const handleSuffix = (value) => {
// store.step1.suffix.value=value.value
store.updateStep1('suffix', { value: value.value });
};
// دالة لإضافة رقم هاتف جديد
const addPhoneNumber = () => {
phoneNumbers.value.push({ phone: '' });
};
// دالة لحذف رقم هاتف
const removePhoneNumber = (index) => {
phoneNumbers.value.splice(index, 1);
};
// دالة لتحديث رقم هاتف
const updatePhoneNumber = (index, value) => {
store.updatePhoneNumber(index, value);
};
// دالة لإضافة Alias Name جديد
const addAliasName = () => {
aliasNames.value.push({ id:uuidv4(), first_name: '', last_name: '', middle_name: '' });
};
// دالة لحذف Alias Name
const removeAliasName = (index) => {
aliasNames.value.splice(index, 1);
};
// دالة لتحديث Alias Name
const updateAliasName = (index, value) => {
store.updateAliasName(index, value);
};
// دالة الحفظ
const save = async () => {
try {
console.log("*-*-*-*-*-*-**-*-",aliasNames)
console.log("*+*+*+*+*+*+*++*",phoneNumbers)
// store.updateStep1('phone', phoneNumbers.value);
// store.updateStep1('alias_name', aliasNames.value);
loading.value = true;
await store.saveStep1();
} catch (error) {
// معالجة الخطأ
} finally {
loading.value = false;
}
};
</script>
<style scoped>
/* أضف تنسيقات إضافية إذا لزم الأمر */
</style> ```
<template>
<div class="pt-3 container">
<h1 class="text-3xl font-bold mb-3 text-black">Personal Information</h1>
<ul>
<li>All fields marked with an asterisk ( * ) are required.</li>
<li>Providing your information as completely and accurately as possible will help speed up the completion of your Background Verification</li>
</ul>
<div class="lg:grid grid-rows-2 lg:gap-2">
<h1 class="text-lg font-medium mb-1 mt-4 text-black">Name</h1>
<Info
text="Please provide your name exactly as it appears on your current government-issued identification document such as your Passport, Driver’s License or National Identification Document"
/>
</div>
<div class="lg:grid grid-cols-2 lg:gap-2">
<FieldContainer>
<StyledInput
labelText="Employer Name"
:isMandatory="true"
infoText="Employer Name"
inputType="text"
v-model="employerName"
:isValid="store.step1.employer_name.isValid"
:validationMessage="store.step1.employer_name.validationMessage"
name="employer_name"
id="EmployerName"
/>
<SupportingText>Supporting text</SupportingText>
</FieldContainer>
<FieldContainer>
<StyledInput
labelText="First Name"
:isMandatory="true"
infoText="First Name"
inputType="text"
v-model="firstName"
:isValid="store.step1.first_name.isValid"
:validationMessage="store.step1.first_name.validationMessage"
name="first_name"
id="firstName"
/>
</FieldContainer>
</div>
<FieldContainer>
<CheckBox
name="dont_middle_name"
id="dont_middle_name"
v-model="dontMiddleName"
>
I certify that I do not have a Middle Name on my official identification document
</CheckBox>
</FieldContainer>
<div class="lg:grid grid-cols-2 lg:gap-2">
<FieldContainer v-if="!dontMiddleName">
<StyledInput
labelText="Middle Name"
inputType="text"
v-model="middleName"
:isValid="store.step1.middle_name.isValid"
:validationMessage="store.step1.middle_name.validationMessage"
name="middle_name"
id="MiddleName"
/>
</FieldContainer>
</div>
<div class="lg:grid grid-cols-2 lg:gap-2">
<FieldContainer>
<StyledInput
labelText="Last Name"
:isMandatory="true"
infoText="Last Name"
inputType="text"
v-model="lastName"
:isValid="store.step1.last_name.isValid"
:validationMessage="store.step1.last_name.validationMessage"
name="last_name"
id="lastName"
/>
</FieldContainer>
<FieldContainer>
<Autocomp
id="suffix"
name="suffix"
labelText="Suffix"
infoText="Select your suffix"
inputType="text"
:options="suffixOptions"
@input-change="handleSuffix"
v-model="suffix"
:isValid="store.step1.suffix.isValid"
:validationMessage="store.step1.suffix.validationMessage"
/>
</FieldContainer>
</div>
<div class="lg:grid grid-cols-2 lg:gap-2">
<FieldContainer>
<Autocomp
name="country_now"
id="country"
labelText="Country"
infoText="Select your country"
inputType="text"
:options="optionCountry"
@input-change="handleCountryChange"
v-model="country"
:isValid="store.step1.country_now.isValid"
:validationMessage="store.step1.country_now.validationMessage"
/>
</FieldContainer>
<FieldContainer>
<Textarea
id="street_address"
name="street_address"
labelText="Street Address"
labelColor="blue"
infoText="Street Address"
size="xl"
v-model="streetAddress"
:isValid="store.step1.street_address.isValid"
:validationMessage="store.step1.street_address.validationMessage"
/>
</FieldContainer>
<FieldContainer>
<Autocomp
name="city"
id="city"
labelText="City"
infoText="City"
inputType="text"
:options="optionCity"
@input-change="handleCityChange"
v-model="city"
:isValid="store.step1.city.isValid"
:validationMessage="store.step1.city.validationMessage"
/>
</FieldContainer>
<FieldContainer>
<Autocomp
name="governorate"
id="governorate"
labelText="Governorate"
infoText="Governorate"
inputType="text"
:options="optionGovernorate"
@input-change="handleGovernorateChange"
v-model="governorate"
:isValid="store.step1.governorate.isValid"
:validationMessage="store.step1.governorate.validationMessage"
/>
</FieldContainer>
<FieldContainer>
<StyledInput
labelText="Location Text"
:isMandatory="true"
infoText="Location Text"
inputType="text"
v-model="locationText"
:isValid="store.step1.location_text.isValid"
:validationMessage="store.step1.location_text.validationMessage"
name="location_text"
id="locationText"
/>
</FieldContainer>
<FieldContainer>
<StyledInput
labelText="Zip Code"
:isMandatory="true"
infoText="Zip Code"
inputType="text"
v-model="zipCode"
:isValid="store.step1.zip_code.isValid"
:validationMessage="store.step1.zip_code.validationMessage"
name="zip_code"
id="zipCode"
/>
</FieldContainer>
<FieldContainer>
<StyledInput
id="date_living_address"
name="date_living_address"
labelText="Date you started living at this address"
:isMandatory="true"
infoText="End date of your education."
inputType="date"
v-model="dateLivingAddress"
:isValid="store.step1.zip_code.isValid"
:validationMessage="store.step1.zip_code.validationMessage"
/>
</FieldContainer>
</div>
<FieldContainer>
<CheckBox
name="this_is_my_name_column"
id="this_is_my_name_column"
v-model="thisIsMyNameColumn"
>
I certify this is my current legal name, exactly as it is displayed on my government-issued identification document *
</CheckBox>
</FieldContainer>
<div class="lg:grid grid-rows-2 lg:gap-2">
<h1 class="text-lg font-medium text-black">Alias Name</h1>
<Info
text="Skip this section if you do not have any alias names.
Please provide:
Any other names appearing on government-issued identity documents where that name differs from your primary identity document; or
A prior legal name which can include your birth surname or any official change to a legal name; or
A name that you use in an “official” capacity."
/>
</div>
<!-- إضافة قسم Alias Name -->
<div class="lg:grid grid-cols-1 lg:gap-2">
<h1 class="text-lg font-medium mb-1 mt-4 text-black">Alias Name</h1>
<Info text="Please provide your alias name." />
<!-- جدول فرعي لAlias Name -->
<div v-for="(alias, index) in aliasNames" :key="alias.id" class="flex items-center mb-2">
<FieldContainer>
<StyledInput
labelText="Full Name"
inputType="text"
v-model="aliasNames[index].first_name"
:isValid="true"
:validationMessage="''"
name="first_name"
:id="aliasNames[index].id"
@input="updateAliasName(index, aliasNames[index])"
/>
</FieldContainer>
<FieldContainer>
<StyledInput
labelText="Middle Name"
inputType="text"
v-model="aliasNames[index].middle_name"
:isValid="true"
:validationMessage="''"
name="middle_name"
:id="aliasNames[index].id"
@input="updateAliasName(index, aliasNames[index])"
/>
</FieldContainer>
<FieldContainer>
<StyledInput
labelText="Last Name"
inputType="text"
v-model="aliasNames[index].last_name"
:isValid="true"
:validationMessage="''"
name="last_name"
:id="aliasNames[index].id"
@input="updateAliasName(index, aliasNames[index])"
/>
</FieldContainer>
<!-- زر حذف Alias Name -->
<Button @click="removeAliasName(index)" class="ml-2 bg-red-500 hover:bg-red-700 text-white font-bold py-2 px-4 rounded">
Remove
</Button>
</div>
<!-- زر إضافة Alias Name جديد -->
<Button @click="addAliasName" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
Add Alias Name
</Button>
</div>
<div class="lg:grid grid-cols-1 lg:gap-2">
<FieldContainer>
<StyledInput
labelText="Email"
:isMandatory="true"
infoText="Please enter your email address"
inputType="email"
name="email"
id="email"
v-model="email"
:isValid="store.step1.email.isValid"
:validationMessage="store.step1.email.validationMessage"
/>
</FieldContainer>
<Info
text="Taakd may occasionally need to contact you for clarification of items on your Background Verification. We will never share or sell your email address."
/>
</div>
<!-- إضافة قسم أرقام الهواتف -->
<div class="lg:grid grid-cols-1 lg:gap-2">
<h1 class="text-lg font-medium mb-1 mt-4 text-black">Phone Numbers</h1>
<Info text="Please provide your phone numbers. You can add multiple phone numbers." />
<!-- جدول فرعي لأرقام الهواتف -->
<div v-for="(phone, index) in phoneNumbers" :key="index" class="flex items-center mb-2">
<FieldContainer>
<StyledInput
labelText="Phone"
inputType="text"
v-model="phoneNumbers[index].phone"
:isValid="true"
:validationMessage="''"
name="phone"
id="phone"
@input="updatePhoneNumber(index, phoneNumbers[index])"
/>
</FieldContainer>
<!-- زر حذف رقم الهاتف -->
<Button @click="removePhoneNumber(index)" class="ml-2 bg-red-500 hover:bg-red-700 text-white font-bold py-2 px-4 rounded">
Remove
</Button>
</div>
<!-- زر إضافة رقم هاتف جديد -->
<Button @click="addPhoneNumber" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
Add Phone Number
</Button>
</div>
<div class="lg:grid grid-ows-2 lg:gap-2">
<h1 class="text-lg font-medium text-black">Identification</h1>
<Info
text="Most public records are stored using your name and birth date, so providing this information allows us to accurately search these sources."
/>
</div>
<div class="lg:grid grid-cols-2 lg:gap-2">
<!-- Date of Birth -->
<FieldContainer>
<StyledInput
id="date_of_birth"
name="date_of_birth"
labelText="Date of Birth"
infoText="Start date of your education."
inputType="date"
v-model="dateOfBirth"
:isValid="store.step1.date_of_birth.isValid"
:validationMessage="store.step1.date_of_birth.validationMessage"
/>
</FieldContainer>
</div>
<div class="pt-5 flex w-full justify-center">
<Button level="other" @click="save" :disabled="loading" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
<span v-if="loading">جاري الحفظ...</span>
<span v-else>save -></span>
</Button>
</div>
</div>
</template>
<script setup lang="ts">
import { computed, ref } from 'vue';
import { useVerificationRequestStore } from '../../stores/verificationRequest';
import CheckBox from '../../components/checkBox.vue';
import FieldContainer from '../../components/fieldContainer.vue';
import StyledInput from '../../components/styledInput.vue';
import SupportingText from '../../components/supportingText.vue';
import Info from './components/info.vue';
import { useToast } from 'vue-toastification';
import Button from '../../components/button.vue';
import Autocomp from '../../components/autocomp.vue';
import Textarea from '../../components/textarea.vue';
import { useLocation } from '../../stores/locations';
import { v4 as uuidv4 } from 'uuid';
const store = useVerificationRequestStore();
const toast = useToast();
const locations = useLocation();
const location = locations.getLocation();
// تعريف متغيرات التحميل
const loading = ref(false);
const phoneNumbers = ref([{ phone: '' }]);
const aliasNames = ref([{ id: uuidv4(), first_name: '', last_name: '', middle_name: '' }]);
// خيارات Suffix
const suffixOptions = [
{ label: 'Jr.', value: 'Jr.' },
{ label: 'Sr.', value: 'Sr.' },
{ label: 'III', value: 'III' },
{ label: 'PhD', value: 'PhD' },
{ label: 'MD', value: 'MD' },
{ label: 'Esq.', value: 'Esq.' },
];
// خيارات الدولة
const optionCountry = computed(() => {
if (location && location.data) {
return location.data
.filter((loc) => loc.location_type === 'Country')
.map((loc) => ({
label: loc.location_name,
value: loc.location_name,
}));
}
return []; // إرجاع مصفوفة فارغة إذا لم تتوفر البيانات.
});
// فلترة المدن بناءً على الدولة
const optionCity = computed(() => {
if (location && location.data && country.value) {
return location.data
.filter(loc => loc.location_type === 'City' && loc.parent_location === country.value)
.map(loc => ({
label: loc.location_name,
value: loc.location_name,
}));
}
return [];
});
// فلترة المحافظات بناءً على المدينة
const optionGovernorate = computed(() => {
if (location && location.data && city.value) {
return location.data
.filter(loc => loc.location_type === 'Governorate' && loc.parent_location === city.value)
.map(loc => ({
label: loc.location_name,
value: loc.location_name,
}));
}
return [];
});
// تعريف computed properties لربط v-model مع مخزن Pinia
const employerName = computed({
get: () => store.step1.employer_name.value,
set: (val: string) => store.updateStep1('employer_name', { value: val }),
});
const firstName = computed({
get: () => store.step1.first_name.value,
set: (val: string) => store.updateStep1('first_name', { value: val }),
});
const lastName = computed({
get: () => store.step1.last_name.value,
set: (val: string) => store.updateStep1('last_name', { value: val }),
});
const dontMiddleName = computed({
get: () => store.step1.dont_middle_name.value,
set: (val: boolean) => store.updateStep1('dont_middle_name', { value: val }),
});
const middleName = computed({
get: () => store.step1.middle_name.value,
set: (val: string) => store.updateStep1('middle_name', { value: val }),
});
const thisIsMyNameColumn = computed({
get: () => store.step1.this_is_my_name_column.value,
set: (val: boolean) => store.updateStep1('this_is_my_name_column', { value: val }),
});
const suffix = computed({
get: () => store.step1.suffix.value,
set: (val: string) => store.updateStep1('suffix', { value: val }),
});
const country = computed({
get: () => store.step1.country_now.value,
set: (val: string) => store.updateStep1('country_now', { value: val }),
});
const governorate = computed({
get: () => store.step1.governorate.value,
set: (val: string) => store.updateStep1('governorate', { value: val }),
});
const city = computed({
get: () => store.step1.city.value,
set: (val: string) => store.updateStep1('city', { value: val }),
});
const locationText = computed({
get: () => store.step1.location_text.value,
set: (val: string) => store.updateStep1('location_text', { value: val }),
});
const streetAddress = computed({
get: () => store.step1.street_address.value,
set: (val: string) => store.updateStep1('street_address', { value: val }),
});
const zipCode = computed({
get: () => store.step1.zip_code.value,
set: (val: string) => store.updateStep1('zip_code', { value: val }),
});
const dateLivingAddress = computed({
get: () => store.step1.date_living_address.value,
set: (val: string) => store.updateStep1('date_living_address', { value: val }),
});
const email = computed({
get: () => store.step1.email.value,
set: (val: string) => store.updateStep1('email', { value: val }),
});
const dateOfBirth = computed({
get: () => store.step1.date_of_birth.value,
set: (val: string) => store.updateStep1('date_of_birth', { value: val }),
});
// معالجة تغيير اختيار الدولة
const handleCountryChange = (value) => {
store.updateStep1('country_now', { value: value.value });
};
const handleCityChange = (value) => {
store.updateStep1('city', { value: value.value });
};
const handleGovernorateChange = (value) => {
store.updateStep1('governorate', { value: value.value });
};
const handleSuffix = (value) => {
store.updateStep1('suffix', { value: value.value });
};
// دالة لإضافة رقم هاتف جديد
const addPhoneNumber = () => {
phoneNumbers.value.push({ id: uuidv4(), phone: '' });
};
// دالة لحذف رقم هاتف
const removePhoneNumber = (index) => {
phoneNumbers.value.splice(index, 1);
};
// دالة لتحديث رقم هاتف
const updatePhoneNumber = (index, phone) => {
store.updatePhoneNumber(index, phone);
};
// دالة لإضافة Alias Name جديد
const addAliasName = () => {
aliasNames.value.push({ id: uuidv4(), first_name: '', last_name: '', middle_name: '' });
};
// دالة لحذف Alias Name
const removeAliasName = (index) => {
aliasNames.value.splice(index, 1);
};
// دالة لتحديث Alias Name
const updateAliasName = (index, alias) => {
store.updateAliasName(index, alias);
};
// دالة الحفظ
const save = async () => {
try {
loading.value = true;
await store.saveStep1();
} catch (error) {
const toast = useToast();
toast.error("حدث خطأ أثناء الحفظ.");
} finally {
loading.value = false;
}
};
</script>
<style scoped>
/* أضف تنسيقات إضافية إذا لزم الأمر */
</style>
ملاحظات حول الكود:
إضافة أرقام الهواتف وأسماء المستعارة: تم دمج وظائف لإضافة وحذف وتحديث أرقام الهواتف وأسماء المستعارة.
وظائف الحفظ: تم إطلاق محاولة لحفظ المعلومات المدخلة، مع معالجة الأخطاء.
التحقق من صحة المدخلات: يتم التحقق من صحة الحقول عبر store.step1 كما تم تحديده في نموذج FormField.
إذا كان لديك أي استفسارات أخرى أو تحتاج لشيء إضافي، فلا تتردد في السؤال!
import { defineStore } from 'pinia';
import {
HomeData,
Step1Data,
Step2Data,
Step3Data,
Step4Data,
Step6Data,
RequestData,
ValidationResult,
UpdateFields,
} from '../data/types';
import { createDocumentResource } from 'frappe-ui';
import { useToast } from 'vue-toastification';
import axios from 'axios';
interface StepValidation {
validation: ValidationResult;
}
interface VerificationRequestStoreState {
documentName: string | null;
home: HomeData;
step1: Step1Data;
step2: Step2Data;
step3: Step3Data;
step4: Step4Data;
step6: Step6Data;
validations: StepValidation[];
}
const getDefaultState = (): VerificationRequestStoreState => ({
documentName: null,
home: {
country: { value: '', isValid: false, validationMessage: '' },
mobile_number: { value: '', isValid: false, validationMessage: '' },
is_degree_or_diploma: { value: false, isValid: false, validationMessage: '' },
from_time: { value: '', isValid: false, validationMessage: '' },
to_time: { value: '', isValid: false, validationMessage: '' },
},
step1: {
employer_name: { value: '', isValid: false, validationMessage: '' },
first_name: { value: '', isValid: false, validationMessage: '' },
last_name: { value: '', isValid: false, validationMessage: '' },
dont_middle_name: { value: false, isValid: false, validationMessage: '' },
middle_name: { value: '', isValid: true, validationMessage: '' },
this_is_my_name_column: { value: false, isValid: false, validationMessage: '' },
suffix: { value: '', isValid: true, validationMessage: '' },
alias_name: [],
country_now: { value: '', isValid: false, validationMessage: '' },
city: { value: '', isValid: false, validationMessage: '' },
governorate: { value: '', isValid: false, validationMessage: '' },
zip_code: { value: '', isValid: false, validationMessage: '' },
location_text: { value: '', isValid: false, validationMessage: '' },
street_address: { value: '', isValid: false, validationMessage: '' },
date_living_address: { value: '', isValid: false, validationMessage: '' },
phone: [],
email: { value: '', isValid: false, validationMessage: '' },
date_of_birth: { value: '', isValid: false, validationMessage: '' },
},
step2: {
educationInformation: [],
},
step3: {
employment_history: [],
},
step4: {
professional_qualification: [],
},
step6: {
other_languages: { value: [] as string[], isValid: true, validationMessage: '' },
electronic_signature: { value: '', isValid: false, validationMessage: '' },
full_name: { value: '', isValid: false, validationMessage: '' },
email_address: { value: '', isValid: false, validationMessage: '' },
i_agree_to_the_electronic_signature: { value: false, isValid: false, validationMessage: '' },
i_acknowledge_the_above: { value: false, isValid: false, validationMessage: '' },
},
validations: Array.from({ length: 5 }, () => ({ validation: {} })),
});
export const useVerificationRequestStore = defineStore('verificationRequest', {
state: (): VerificationRequestStoreState => getDefaultState(),
actions: {
// تعيين اسم الوثيقة
setDocumentName(name: string) {
this.documentName = name;
},
/**
* تحميل الوثيقة الحالية
*/
async loadDocument() {
const toast = useToast();
try {
await this.loadHomeFields();
await this.loadStep1Fields();
await this.loadStep2Fields();
await this.loadStep3Fields();
await this.loadStep4Fields();
await this.loadStep6Fields();
} catch (error) {
console.error("Error loading document:", error);
toast.error("حدث خطأ أثناء تحميل الوثيقة.");
}
},
// دوال تحديث الحقول لمختلف الخطوات
updateHome<K extends keyof VerificationRequestStoreState['home']>(
field: K,
payload: Partial<VerificationRequestStoreState['home'][K]>
) {
this.home[field] = { ...this.home[field], ...payload };
},
updateStep1<K extends keyof VerificationRequestStoreState['step1']>(
field: K,
payload: Partial<VerificationRequestStoreState['step1'][K]>
) {
this.step1[field] = { ...this.step1[field], ...payload };
},
updateStep2<K extends keyof VerificationRequestStoreState['step2']>(
field: K,
payload: Partial<VerificationRequestStoreState['step2'][K]>
) {
this.step2[field] = { ...this.step2[field], ...payload };
},
updateStep3<K extends keyof VerificationRequestStoreState['step3']>(
field: K,
payload: Partial<VerificationRequestStoreState['step3'][K]>
) {
this.step3[field] = { ...this.step3[field], ...payload };
},
updateStep4<K extends keyof VerificationRequestStoreState['step4']>(
field: K,
payload: Partial<VerificationRequestStoreState['step4'][K]>
) {
this.step4[field] = { ...this.step4[field], ...payload };
},
updateStep6<K extends keyof VerificationRequestStoreState['step6']>(
field: K,
payload: Partial<VerificationRequestStoreState['step6'][K]>
) {
this.step6[field] = { ...this.step6[field], ...payload };
},
// إعادة تعيين الستور إلى الحالة الافتراضية
resetStore() {
Object.assign(this, getDefaultState());
},
/**
* إضافة رقم هاتف جديد
*/
addPhoneNumber() {
this.step1.phone.push({ id: `${Date.now()}`, phone: '' });
},
/**
* إزالة رقم هاتف
*/
removePhoneNumber(index: number) {
this.step1.phone.splice(index, 1);
},
/**
* تحديث رقم هاتف معين
*/
updatePhoneNumber(index: number, value: string) {
this.step1.phone[index].phone = value;
},
/**
* التحقق من صحة أرقام الهواتف
*/
validatePhoneNumbers(): boolean {
let isValid = true;
this.step1.phone.forEach((phone, index) => {
if (!phone.phone || phone.phone.trim() === '') {
isValid = false;
this.step1.phone[index].isValid = false;
} else {
this.step1.phone[index].isValid = true;
}
});
return isValid;
},
/**
* تحديث اسم مستعار
*/
updateAliasName(index: number, value: { first_name: string; last_name: string; middle_name: string }) {
this.step1.alias_name[index] = value;
},
async updateDocumentFields(updatedFields: UpdateFields) {
const toast = useToast();
if (!this.documentName) {
toast.error("لم يتم العثور على اسم الوثيقة. يرجى إنشاء وثيقة أولاً.");
return;
}
try {
const request = createDocumentResource({
doctype: 'Verification Instructions Request',
name: this.documentName,
});
await request.setValue.submit(updatedFields);
toast.success("تم تحديث الوثيقة بنجاح.");
} catch (error) {
console.error("Error updating document fields:", error);
toast.error("حدث خطأ أثناء تحديث الوثيقة.");
throw new Error('Error updating document fields');
}
},
/**
* دالة التحقق من صحة بيانات Step 1
*/
validateStep1(): boolean {
let isValid = true;
const requiredFields: (keyof Step1Data)[] = [
'employer_name',
'first_name',
'last_name',
// 'country_now',
// 'city',
// 'governorate',
'zip_code',
'location_text',
// 'street_address',
'date_living_address',
'email',
'date_of_birth',
];
requiredFields.forEach((field) => {
const fieldData = this.step1[field];
if (!fieldData.value || (Array.isArray(fieldData.value) && fieldData.value.length === 0)) {
this.updateStep1(field, {
isValid: false,
validationMessage: 'هذا الحقل مطلوب.',
});
isValid = false;
} else {
this.updateStep1(field, {
isValid: true,
validationMessage: '',
});
}
});
const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (this.step1.email.value && !emailPattern.test(this.step1.email.value)) {
this.updateStep1('email', {
isValid: false,
validationMessage: 'يرجى إدخال بريد إلكتروني صحيح.',
});
isValid = false;
} else if (this.step1.email.value) {
this.updateStep1('email', {
isValid: true,
validationMessage: '',
});
}
return isValid;
},
/**
* دالة التحقق من صحة بيانات Step 2
*/
validateStep2(): boolean {
let isValid = true;
this.step2.educationInformation.forEach(education => {
if (!education.name_of_school_or_college_university || !education.field_of_study_or_major) {
isValid = false;
}
});
return isValid;
},
/**
* دالة التحقق من صحة بيانات Step 3
*/
validateStep3(): boolean {
let isValid = true;
this.step3.employment_history.forEach((employment, index) => {
if (
!employment.company ||
!employment.name_of_your_employer ||
!employment.country ||
!employment.city ||
!employment.governorate ||
!employment.from_date ||
!employment.end_date ||
!employment.phone ||
!employment.official_job_title_held_currently
) {
isValid = false;
// يمكنك إضافة رسائل تحقق خاصة لكل حقل إذا لزم الأمر
}
});
return isValid;
},
/**
* دالة التحقق من صحة بيانات Step 4
*/
validateStep4(): boolean {
let isValid = true;
this.step4.professional_qualification.forEach((qualification, index) => {
if (
!qualification.awarding_body ||
!qualification.license_or_certificate_number ||
!qualification.issuing_country ||
!qualification.date_awarded ||
!qualification.award_name_description
) {
isValid = false;
}
if (qualification.is_an_expiration_date && (!qualification.expiration_date || qualification.expiration_date.trim() === '')) {
isValid = false;
}
});
return isValid;
},
/**
* دالة التحقق من صحة بيانات Step6
*/
validateStep6(): boolean {
let isValid = true;
const requiredFields: (keyof Step6Data)[] = [
'full_name',
'email_address',
'i_acknowledge_the_above',
];
requiredFields.forEach((field) => {
const fieldData = this.step6[field];
if (fieldData.value === false || !fieldData.value || (Array.isArray(fieldData.value) && fieldData.value.length === 0)) {
this.updateStep6(field, {
isValid: false,
validationMessage: 'هذا الحقل مطلوب.',
});
isValid = false;
} else {
this.updateStep6(field, {
isValid: true,
validationMessage: '',
});
}
});
const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (this.step6.email_address.value && !emailPattern.test(this.step6.email_address.value)) {
this.updateStep6('email_address', {
isValid: false,
validationMessage: 'يرجى إدخال بريد إلكتروني صحيح.',
});
isValid = false;
} else if (this.step6.email_address.value) {
this.updateStep6('email_address', {
isValid: true,
validationMessage: '',
});
}
// التحقق من التوقيع الإلكتروني والموافقة
if (!this.step6.electronic_signature.value) {
this.updateStep6('electronic_signature', {
isValid: false,
validationMessage: 'التوقيع الإلكتروني مطلوب.',
});
isValid = false;
} else {
this.updateStep6('electronic_signature', {
isValid: true,
validationMessage: '',
});
}
if (!this.step6.i_agree_to_the_electronic_signature.value) {
this.updateStep6('i_agree_to_the_electronic_signature', {
isValid: false,
validationMessage: 'يجب الموافقة على التوقيع الإلكتروني.',
});
isValid = false;
} else {
this.updateStep6('i_agree_to_the_electronic_signature', {
isValid: true,
validationMessage: '',
});
}
if (!this.step6.i_acknowledge_the_above.value) {
this.updateStep6('i_acknowledge_the_above', {
isValid: false,
validationMessage: 'يجب تأكيد التوقيع الإلكتروني.',
});
isValid = false;
} else {
this.updateStep6('i_acknowledge_the_above', {
isValid: true,
validationMessage: '',
});
}
return isValid;
},
/**
* دالة الحفظ لخطوة Step 1
*/
async saveStep1() {
const toast = useToast();
// التحقق من صحة البيانات
if (!this.validateStep1()) {
toast.error('يرجى تصحيح الأخطاء قبل الحفظ.');
throw new Error('Validation failed');
}
// تجهيز البيانات للإرسال
const dataToSubmit: UpdateFields = {};
for (const key in this.step1) {
if (Object.prototype.hasOwnProperty.call(this.step1, key)) {
const field = key as keyof Step1Data;
dataToSubmit[key] = this.step1[field].value;
}
}
try {
await this.updateDocumentFields(dataToSubmit);
toast.success('تم حفظ البيانات بنجاح.');
} catch (error) {
throw error;
}
},
/**
* دالة الحفظ لخطوة Step2
*/
async saveStep2() {
const toast = useToast();
if (!this.validateStep2()) {
toast.error('يرجى تصحيح الأخطاء قبل الحفظ.');
throw new Error('Validation failed');
}
const dataToSubmit: UpdateFields = {
education_information: this.step2.educationInformation,
};
// رفع الملفات المرتبطة بالتوظيف هنا إذا كانت موجودة
const savePromises = this.step3.employment_history.map(async (employment) => {
if (employment.file && employment.file instanceof File) { // تأكد أن الملف هو كائن File
try {
const uploadedFile = await this.uploadFile(employment.id, employment.file as File);
// تحديث حقل الملف برابطه المرفوع
employment.file = uploadedFile.file_url; // تخزين رابط الملف في الحالة
} catch (error) {
toast.error(`فشل رفع الملف للسجل: ${employment.company}.`);
throw error;
}
}
});
try {
await Promise.all(savePromises);
toast.success('تم رفع الملفات بنجاح.');
} catch (error) {
console.error('Error uploading files:', error);
toast.error('فشل رفع بعض الملفات.');
throw error;
}
try {
await this.updateDocumentFields(dataToSubmit);
toast.success('تم حفظ بيانات التعليم بنجاح.');
} catch (error) {
throw error;
}
},
/**
* دالة الحفظ لخطوة Step3
*/
async saveStep3() {
const toast = useToast();
if (!this.validateStep3()) {
toast.error('يرجى تصحيح الأخطاء قبل الحفظ.');
throw new Error('Validation failed');
}
// معالجة رفع الملفات أولاً
const uploadPromises = this.step3.employment_history.map(async (employment, index) => {
if (employment.file instanceof File) { // تحقق إذا كان الملف كائن File
try {
const uploadedFile = await this.uploadFile(employment.id, employment.file);
employment.file = uploadedFile.file_url; // تخزين رابط الملف المرفوع
} catch (error) {
toast.error(`فشل رفع الملف للسجل رقم ${index + 1}.`);
throw new Error(`File upload failed for employment index ${index}`);
}
}
});
// انتظار رفع جميع الملفات
try {
await Promise.all(uploadPromises);
} catch (error) {
console.error('Error uploading files:', error);
throw error;
}
// تجهيز البيانات للإرسال بعد رفع الملفات
const dataToSubmit: UpdateFields = {
employment_history: this.step3.employment_history.map(employment => ({
...employment,
file: employment.file, // الآن يجب أن يكون الرابط النصي للملف
})),
};
// حفظ بيانات التوظيف إلى الـ Doctype
try {
await this.updateDocumentFields(dataToSubmit);
toast.success('تم حفظ بيانات التوظيف بنجاح.');
} catch (error) {
console.error('حدث خطأ أثناء حفظ بيانات التوظيف:', error);
toast.error('حدث خطأ أثناء حفظ بيانات التوظيف.');
throw error;
}
},
/**
* دالة الحفظ لخطوة Step4
*/
async saveStep4() {
const toast = useToast();
if (!this.validateStep4()) {
toast.error('يرجى تصحيح الأخطاء قبل الحفظ.');
throw new Error('Validation failed');
}
const dataToSubmit: UpdateFields = {
professional_qualification: this.step4.professional_qualification,
};
try {
await this.updateDocumentFields(dataToSubmit);
toast.success('تم حفظ بيانات المؤهلات المهنية الإضافية بنجاح.');
} catch (error) {
console.error('حدث خطأ أثناء حفظ بيانات المؤهلات المهنية الإضافية:', error);
toast.error('حدث خطأ أثناء حفظ بيانات المؤهلات المهنية الإضافية.');
throw error;
}
},
/**
* دالة الحفظ لخطوة Step6
*/
async saveStep6() {
const toast = useToast();
// التحقق من صحة البيانات
if (!this.validateStep6()) {
toast.error('يرجى تصحيح الأخطاء قبل الحفظ.');
throw new Error('Validation failed');
}
// تجهيز البيانات للإرسال
const dataToSubmit: UpdateFields = {};
for (const key in this.step6) {
if (Object.prototype.hasOwnProperty.call(this.step6, key)) {
const field = key as keyof Step6Data;
dataToSubmit[key] = this.step6[field].value;
}
}
// إرسال البيانات إلى Doctype
try {
await this.updateDocumentFields(dataToSubmit);
toast.success('تم حفظ البيانات بنجاح.');
} catch (error) {
throw error;
}
},
/**
* دالة تحميل الملف إلى الـ Doctype
* @param employmentId معرف التوظيف (uuid)
* @param file الملف الذي سيتم تحميله
*/
async uploadFile(employmentId: string, file: File) {
if (!this.documentName) {
throw new Error('Document name is not set.');
}
const formData = new FormData();
formData.append('filedata', file);
formData.append('doctype', 'Verification Instructions Request');
formData.append('docname', this.documentName);
formData.append('fieldname', 'file'); // تأكد من أن الحقل هو 'file' داخل الجدول الفرعي
formData.append('parentfield', 'employment_history'); // اسم جدول التوظيف الفرعي
formData.append('parenttype', 'Verification Instructions Request');
formData.append('employment_id', employmentId); // لربط الملف بسجل التوظيف المحدد
try {
const response = await axios.post(
'/api/method/taakd_app.taakd_app.doctype.verification_instructions_request.verification_instructions_request.upload_verification_file', // استبدل 'taakd_app' باسم تطبيقك الفعلي
formData,
{
headers: {
'Content-Type': 'multipart/form-data',
},
}
);
return response.data; // تأكد من المسار الصحيح للملف في الاستجابة
} catch (error) {
console.error('Error uploading file:', error);
throw error;
}
},
/**
* دوال تحميل الحقول لكل خطوة
*/
async loadHomeFields() {
try {
const request = createDocumentResource({
doctype: 'Verification Instructions Request',
name: this.documentName,
});
const data = await request.reload();
// تحديث الحقول في Home
this.updateHome('country', { value: data.country });
this.updateHome('mobile_number', { value: data.mobile_number });
this.updateHome('is_degree_or_diploma', { value: data.is_degree_or_diploma });
this.updateHome('from_time', { value: data.from_time });
this.updateHome('to_time', { value: data.to_time });
} catch (error) {
console.error("Error loading Home fields:", error);
const toast = useToast();
toast.error("حدث خطأ أثناء تحميل بيانات الحقول الرئيسية.");
}
},
async loadStep1Fields() {
try {
const request = createDocumentResource({
doctype: 'Verification Instructions Request',
name: this.documentName,
});
const data = await request.reload();
// تحديث الحقول في Step1
this.updateStep1('employer_name', { value: data.employer_name });
this.updateStep1('first_name', { value: data.first_name });
this.updateStep1('last_name', { value: data.last_name });
this.updateStep1('dont_middle_name', { value: data.dont_middle_name });
this.updateStep1('middle_name', { value: data.middle_name });
this.updateStep1('this_is_my_name_column', { value: data.this_is_my_name_column });
this.updateStep1('suffix', { value: data.suffix });
this.updateStep1('country_now', { value: data.country_now });
this.updateStep1('city', { value: data.city });
this.updateStep1('governorate', { value: data.governorate });
this.updateStep1('zip_code', { value: data.zip_code });
this.updateStep1('location_text', { value: data.location_text });
this.updateStep1('street_address', { value: data.street_address });
this.updateStep1('date_living_address', { value: data.date_living_address });
this.updateStep1('email', { value: data.email });
this.updateStep1('date_of_birth', { value: data.date_of_birth });
// تحميل الحقول الفرعية مثل alias_name و phone إذا كانت موجودة
if (data.alias_name && Array.isArray(data.alias_name)) {
this.step1.alias_name = data.alias_name;
}
if (data.phone && Array.isArray(data.phone)) {
this.step1.phone = data.phone;
}
// يمكنك إضافة المزيد من الحقول بناءً على احتياجاتك
this.validations = data.validations || this.validations; // تحديث التحققات إذا كانت موجودة
} catch (error) {
console.error("Error loading Step1 fields:", error);
const toast = useToast();
toast.error("حدث خطأ أثناء تحميل بيانات الخطوة الأولى.");
}
},
async loadStep2Fields() {
try {
const request = createDocumentResource({
doctype: 'Verification Instructions Request',
name: this.documentName,
});
const data = await request.reload();
// تحديث الحقول في Step2
this.step2.educationInformation = data.education_information;
} catch (error) {
console.error("Error loading Step2 fields:", error);
const toast = useToast();
toast.error("حدث خطأ أثناء تحميل بيانات الخطوة الثانية.");
}
},
async loadStep3Fields() {
try {
const request = createDocumentResource({
doctype: 'Verification Instructions Request',
name: this.documentName,
});
const data = await request.reload();
// تحديث الحقول في Step3
this.step3.employment_history = data.employment_history;
} catch (error) {
console.error("Error loading Step3 fields:", error);
const toast = useToast();
toast.error("حدث خطأ أثناء تحميل بيانات الخطوة الثالثة.");
}
},
async loadStep4Fields() {
try {
const request = createDocumentResource({
doctype: 'Verification Instructions Request',
name: this.documentName,
});
const data = await request.reload();
// تحديث الحقول في Step4
this.step4.professional_qualification = data.professional_qualification;
} catch (error) {
console.error("Error loading Step4 fields:", error);
const toast = useToast();
toast.error("حدث خطأ أثناء تحميل بيانات الخطوة الرابعة.");
}
},
async loadStep6Fields() {
try {
const request = createDocumentResource({
doctype: 'Verification Instructions Request',
name:this.documentName,
});
const data = await request.reload(); // تأكد من كيفية جلب البيانات حسب مكتبة frappe-ui
// تحديث الحقول في Step6
this.updateStep6('other_languages', { value: data.other_languages });
this.updateStep6('electronic_signature', { value: data.electronic_signature });
this.updateStep6('full_name', { value: data.full_name });
this.updateStep6('email_address', { value: data.email_address });
this.updateStep6('i_agree_to_the_electronic_signature', { value: data.i_agree_to_the_electronic_signature });
this.updateStep6('acknowledge_electronic_signature', { value: data.acknowledge_electronic_signature });
this.updateStep6('i_acknowledge_the_above', { value: data.i_acknowledge_the_above });
} catch (error) {
console.error("Error loading Step6 fields:", error);
const toast = useToast();
toast.error("حدث خطأ أثناء تحميل بيانات الخطوة السادسة.");
}
},
},
}); ```
// src/stores/verificationRequest.ts
import { defineStore } from 'pinia';
import {
HomeData,
Step1Data,
Step2Data,
Step3Data,
Step4Data,
Step6Data,
RequestData,
ValidationResult,
UpdateFields,
} from '../data/types';
import { createDocumentResource } from 'frappe-ui';
import { useToast } from 'vue-toastification';
import axios from 'axios';
interface StepValidation {
validation: ValidationResult;
}
interface VerificationRequestStoreState {
documentName: string | null;
home: HomeData;
step1: Step1Data;
step2: Step2Data;
step3: Step3Data;
step4: Step4Data;
step6: Step6Data;
validations: StepValidation[];
}
const getDefaultState = (): VerificationRequestStoreState => ({
documentName: null,
home: {
country: { value: '', isValid: false, validationMessage: '' },
mobile_number: { value: '', isValid: false, validationMessage: '' },
is_degree_or_diploma: { value: false, isValid: false, validationMessage: '' },
from_time: { value: '', isValid: false, validationMessage: '' },
to_time: { value: '', isValid: false, validationMessage: '' },
},
step1: {
employer_name: { value: '', isValid: false, validationMessage: '' },
first_name: { value: '', isValid: false, validationMessage: '' },
last_name: { value: '', isValid: false, validationMessage: '' },
dont_middle_name: { value: false, isValid: false, validationMessage: '' },
middle_name: { value: '', isValid: true, validationMessage: '' },
this_is_my_name_column: { value: false, isValid: false, validationMessage: '' },
suffix: { value: '', isValid: true, validationMessage: '' },
alias_name: [], // قائمة بأسماء المستعارة
country_now: { value: '', isValid: false, validationMessage: '' },
city: { value: '', isValid: false, validationMessage: '' },
governorate: { value: '', isValid: false, validationMessage: '' },
zip_code: { value: '', isValid: false, validationMessage: '' },
location_text: { value: '', isValid: false, validationMessage: '' },
street_address: { value: '', isValid: false, validationMessage: '' },
date_living_address: { value: '', isValid: false, validationMessage: '' },
phone: [], // قائمة بأرقام الهواتف
email: { value: '', isValid: false, validationMessage: '' },
date_of_birth: { value: '', isValid: false, validationMessage: '' },
},
step2: {
educationInformation: [],
},
step3: {
employment_history: [],
},
step4: {
professional_qualification: [],
},
step6: {
other_languages: { value: [] as string[], isValid: true, validationMessage: '' },
electronic_signature: { value: '', isValid: false, validationMessage: '' },
full_name: { value: '', isValid: false, validationMessage: '' },
email_address: { value: '', isValid: false, validationMessage: '' },
i_agree_to_the_electronic_signature: { value: false, isValid: false, validationMessage: '' },
i_acknowledge_the_above: { value: false, isValid: false, validationMessage: '' },
},
validations: Array.from({ length: 5 }, () => ({ validation: {} })),
});
export const useVerificationRequestStore = defineStore('verificationRequest', {
state: (): VerificationRequestStoreState => getDefaultState(),
actions: {
// تعيين اسم الوثيقة
setDocumentName(name: string) {
this.documentName = name;
},
/**
* تحميل الوثيقة الحالية
*/
async loadDocument() {
const toast = useToast();
try {
await this.loadHomeFields();
await this.loadStep1Fields();
await this.loadStep2Fields();
await this.loadStep3Fields();
await this.loadStep4Fields();
await this.loadStep6Fields();
} catch (error) {
console.error("Error loading document:", error);
toast.error("حدث خطأ أثناء تحميل الوثيقة.");
}
},
// دوال تحديث الحقول لمختلف الخطوات
updateHome<K extends keyof VerificationRequestStoreState['home']>(
field: K,
payload: Partial<VerificationRequestStoreState['home'][K]>
) {
this.home[field] = { ...this.home[field], ...payload };
},
updateStep1<K extends keyof VerificationRequestStoreState['step1']>(
field: K,
payload: Partial<VerificationRequestStoreState['step1'][K]>
) {
this.step1[field] = { ...this.step1[field], ...payload };
},
updateStep2<K extends keyof VerificationRequestStoreState['step2']>(
field: K,
payload: Partial<VerificationRequestStoreState['step2'][K]>
) {
this.step2[field] = { ...this.step2[field], ...payload };
},
updateStep3<K extends keyof VerificationRequestStoreState['step3']>(
field: K,
payload: Partial<VerificationRequestStoreState['step3'][K]>
) {
this.step3[field] = { ...this.step3[field], ...payload };
},
updateStep4<K extends keyof VerificationRequestStoreState['step4']>(
field: K,
payload: Partial<VerificationRequestStoreState['step4'][K]>
) {
this.step4[field] = { ...this.step4[field], ...payload };
},
updateStep6<K extends keyof VerificationRequestStoreState['step6']>(
field: K,
payload: Partial<VerificationRequestStoreState['step6'][K]>
) {
this.step6[field] = { ...this.step6[field], ...payload };
},
// إعادة تعيين الستور إلى الحالة الافتراضية
resetStore() {
Object.assign(this, getDefaultState());
},
/**
* إضافة رقم هاتف جديد
*/
addPhoneNumber() {
this.step1.phone.push({ id: `${Date.now()}`, phone: '' });
},
/**
* إزالة رقم هاتف
*/
removePhoneNumber(index: number) {
this.step1.phone.splice(index, 1);
},
/**
* تحديث رقم هاتف معين
*/
updatePhoneNumber(index: number, value: string) {
this.step1.phone[index].phone = value;
},
/**
* التحقق من صحة أرقام الهواتف
*/
validatePhoneNumbers(): boolean {
let isValid = true;
this.step1.phone.forEach((phone, index) => {
if (!phone.phone || phone.phone.trim() === '') {
isValid = false;
this.step1.phone[index].isValid = false;
} else {
this.step1.phone[index].isValid = true;
}
});
return isValid;
},
/**
* تحديث اسم مستعار
*/
updateAliasName(index: number, value: { first_name: string; last_name: string; middle_name: string }) {
this.step1.alias_name[index] = value;
},
async updateDocumentFields(updatedFields: UpdateFields) {
const toast = useToast();
if (!this.documentName) {
toast.error("لم يتم العثور على اسم الوثيقة. يرجى إنشاء وثيقة أولاً.");
return;
}
try {
const request = createDocumentResource({
doctype: 'Verification Instructions Request',
name: this.documentName,
});
await request.setValue.submit(updatedFields);
toast.success("تم تحديث الوثيقة بنجاح.");
} catch (error) {
console.error("Error updating document fields:", error);
toast.error("حدث خطأ أثناء تحديث الوثيقة.");
throw new Error('Error updating document fields');
}
},
/**
* دالة التحقق من صحة بيانات Step 1
*/
validateStep1(): boolean {
let isValid = true;
const requiredFields: (keyof Step1Data)[] = [
'employer_name',
'first_name',
'last_name',
'country_now',
'city',
'governorate',
'zip_code',
'location_text',
'date_living_address',
'email',
'date_of_birth',
];
requiredFields.forEach((field) => {
const fieldData = this.step1[field];
if (!fieldData.value || (Array.isArray(fieldData.value) && fieldData.value.length === 0)) {
this.updateStep1(field, {
isValid: false,
validationMessage: 'هذا الحقل مطلوب.',
});
isValid = false;
} else {
this.updateStep1(field, {
isValid: true,
validationMessage: '',
});
}
});
const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (this.step1.email.value && !emailPattern.test(this.step1.email.value)) {
this.updateStep1('email', {
isValid: false,
validationMessage: 'يرجى إدخال بريد إلكتروني صحيح.',
});
isValid = false;
} else if (this.step1.email.value) {
this.updateStep1('email', {
isValid: true,
validationMessage: '',
});
}
return isValid;
},
/**
* دالة الحفظ لخطوة Step 1
*/
async saveStep1() {
const toast = useToast();
// التحقق من صحة البيانات
if (!this.validateStep1()) {
toast.error('يرجى تصحيح الأخطاء قبل الحفظ.');
throw new Error('Validation failed');
}
// تجهيز البيانات للإرسال
const dataToSubmit: UpdateFields = {};
for (const key in this.step1) {
if (Object.prototype.hasOwnProperty.call(this.step1, key)) {
const field = key as keyof Step1Data;
dataToSubmit[key] = this.step1[field].value;
}
}
try {
await this.updateDocumentFields(dataToSubmit);
toast.success('تم حفظ البيانات بنجاح.');
} catch (error) {
throw error;
}
},
// دوال التحميل والإجراء الخاصة بكل خطوة
async loadHomeFields() {
try {
const request = createDocumentResource({
doctype: 'Verification Instructions Request',
name: this.documentName,
});
const data = await request.reload();
// تحديث الحقول في Home
this.updateHome('country', { value: data.country });
this.updateHome('mobile_number', { value: data.mobile_number });
this.updateHome('is_degree_or_diploma', { value: data.is_degree_or_diploma });
this.updateHome('from_time', { value: data.from_time });
this.updateHome('to_time', { value: data.to_time });
} catch (error) {
console.error("Error loading Home fields:", error);
const toast = useToast();
toast.error("حدث خطأ أثناء تحميل بيانات الحقول الرئيسية.");
}
},
async loadStep1Fields() {
try {
const request = createDocumentResource({
doctype: 'Verification Instructions Request',
name: this.documentName,
});
const data = await request.reload();
// تحديث الحقول في Step1
this.updateStep1('employer_name', { value: data.employer_name });
this.updateStep1('first_name', { value: data.first_name });
this.updateStep1('last_name', { value: data.last_name });
this.updateStep1('dont_middle_name', { value: data.dont_middle_name });
this.updateStep1('middle_name', { value: data.middle_name });
this.updateStep1('this_is_my_name_column', { value: data.this_is_my_name_column });
this.updateStep1('suffix', { value: data.suffix });
this.updateStep1('country_now', { value: data.country_now });
this.updateStep1('city', { value: data.city });
this.updateStep1('governorate', { value: data.governorate });
this.updateStep1('zip_code', { value: data.zip_code });
this.updateStep1('location_text', { value: data.location_text });
this.updateStep1('street_address', { value: data.street_address });
this.updateStep1('date_living_address', { value: data.date_living_address });
this.updateStep1('email', { value: data.email });
this.updateStep1('date_of_birth', { value: data.date_of_birth });
// تحميل الحقول الفرعية مثل alias_name و phone إذا كانت موجودة
if (data.alias_name && Array.isArray(data.alias_name)) {
this.step1.alias_name = data.alias_name;
}
if (data.phone && Array.isArray(data.phone)) {
this.step1.phone = data.phone;
}
} catch (error) {
console.error("Error loading Step1 fields:", error);
const toast = useToast();
toast.error("حدث خطأ أثناء تحميل بيانات الخطوة الأولى.");
}
},
async loadStep2Fields() {
try {
const request = createDocumentResource({
doctype: 'Verification Instructions Request',
name: this.documentName,
});
const data = await request.reload();
// تحديث الحقول في Step2
this.step2.educationInformation = data.education_information;
} catch (error) {
console.error("Error loading Step2 fields:", error);
const toast = useToast();
toast.error("حدث خطأ أثناء تحميل بيانات الخطوة الثانية.");
}
},
async loadStep3Fields() {
try {
const request = createDocumentResource({
doctype: 'Verification Instructions Request',
name: this.documentName,
});
const data = await request.reload();
// تحديث الحقول في Step3
this.step3.employment_history = data.employment_history;
} catch (error) {
console.error("Error loading Step3 fields:", error);
const toast = useToast();
toast.error("حدث خطأ أثناء تحميل بيانات الخطوة الثالثة.");
}
},
async loadStep4Fields() {
try {
const request = createDocumentResource({
doctype: 'Verification Instructions Request',
name: this.documentName,
});
const data = await request.reload();
// تحديث الحقول في Step4
this.step4.professional_qualification = data.professional_qualification;
} catch (error) {
console.error("Error loading Step4 fields:", error);
const toast = useToast();
toast.error("حدث خطأ أثناء تحميل بيانات الخطوة الرابعة.");
}
},
async loadStep6Fields() {
try {
const request = createDocumentResource({
doctype: 'Verification Instructions Request',
name: this.documentName,
});
const data = await request.reload();
// تحديث الحقول في Step6
this.updateStep6('other_languages', { value: data.other_languages });
this.updateStep6('electronic_signature', { value: data.electronic_signature });
this.updateStep6('full_name', { value: data.full_name });
this.updateStep6('email_address', { value: data.email_address });
this.updateStep6('i_agree_to_the_electronic_signature', { value: data.i_agree_to_the_electronic_signature });
this.updateStep6('acknowledge_electronic_signature', { value: data.acknowledge_electronic_signature });
this.updateStep6('i_acknowledge_the_above', { value: data.i_acknowledge_the_above });
} catch (error) {
console.error("Error loading Step6 fields:", error);
const toast = useToast();
toast.error("حدث خطأ أثناء تحميل بيانات الخطوة السادسة.");
}
},
},
});
ملاحظات حول الكود:
تحديث أرقام الهواتف : تم تضمين الدوال addPhoneNumber, removePhoneNumber, و updatePhoneNumber المخصصة لإدارة أرقام الهاتف داخل خطوة 1.
تحديث أسماء المستعارة : تمت إضافة دالة updateAliasName لتحديث بيانات أسماء المستعارة.
التحقق من صحة البيانات : تم تضمين دوال فحص البيانات قبل أن يتم حفظها في قاعدة البيانات.
إعادة تعيين الحالة : تمت إضافة دالة resetStore لإعادة جميع الحقول إلى قيمها الافتراضية.
تحميل البيانات : تم تضمين جميع الدوال الضرورية لتحميل بيانات الوثيقة من الخادم.
إذا كنت بحاجة إلى أي تعديلات إضافية أو لديك أسئلة أخرى، فلا تتردد في طرحها!
// واجهة لحقل النموذج
export interface FormField<T = any> {
value: T;
isValid: boolean;
validationMessage: string;
touched?: boolean;
}
// واجهات البيانات لكل خطوة
export interface HomeData {
country: FormField<string>;
mobile_number: FormField<string>;
is_degree_or_diploma: FormField<boolean>;
from_time: FormField<string>;
to_time: FormField<string>;
}
export interface PhoneNumber {
id: string;
phone: string;
}
export interface AliasName {
id: string;
first_name: string;
last_name: string;
middle_name: string;
}
export interface Step1Data {
employer_name: FormField<string>;
first_name: FormField<string>;
last_name: FormField<string>;
dont_middle_name: FormField<boolean>;
middle_name: FormField<string>;
this_is_my_name_column: FormField<boolean>;
suffix: FormField<string>;
alias_name: AliasName[];
country_now: FormField<string>;
city: FormField<string>;
governorate: FormField<string>;
zip_code: FormField<string>;
location_text: FormField<string>;
street_address: FormField<string>;
date_living_address: FormField<string>;
phone: PhoneNumber[];
email: FormField<string>;
date_of_birth: FormField<string>;
}
export interface EducationInformation {
id: string;
name_of_school_or_college_university: string;
country: string;
city: string;
governorate: string;
location_text: string;
from_date: string;
to_date: string;
field_of_study_or_major: string;
phone: string;
ext: string;
diploma: string;
another_name: string;
}
export interface EmploymentHistory {
id: string;
company: string;
name_of_your_employer: string;
contact_the_employer: boolean;
issuing_salary: boolean;
country: string;
city: string;
governorate: string;
location_text: string;
continuous: boolean;
activity_has_stopped: boolean;
from_date: string;
end_date: string;
phone: string;
ext: string;
official_job_title_held_currently: string;
type_of_employment: string;
the_company_has_different_names: boolean;
different_company_names: string;
you_have_a_nicknamecx: boolean;
nickname: string;
file: File | string | null; // دعم كائن File أو رابط الملف (string)
}
export interface ProfessionalQualification {
id: string;
awarding_body: string;
license_or_certificate_number: string;
issuing_country: string;
date_awarded: string;
expiration_date?: string; // اختياري
award_name_description: string;
is_an_expiration_date: boolean;
your_name_varies: boolean;
}
export interface Step2Data {
educationInformation: EducationInformation[];
}
export interface Step3Data {
employment_history: EmploymentHistory[];
}
export interface Step4Data {
professional_qualification: ProfessionalQualification[];
}
export interface Step6Data {
other_languages: FormField<string[]>; // تصحيح النوع إلى string[]
electronic_signature: FormField<string>;
full_name: FormField<string>;
email_address: FormField<string>;
i_agree_to_the_electronic_signature: FormField<boolean>;
i_acknowledge_the_above: FormField<boolean>; // إضافة هذا الحقل
}
export interface ValidationResult {
[key: string]: {
isValid: boolean;
validationMessage?: string;
};
}
// واجهة RequestData: تمثل مجموعة كافة البيانات من الخطوات (للإرسال إلى الخادم)
export interface RequestData {
name: string;
user_id: string;
// Home
country: string;
mobile_number: string;
is_degree_or_diploma: boolean;
from_time: string;
to_time: string;
// Step1
employer_name: string;
first_name: string;
last_name: string;
dont_middle_name: boolean;
middle_name: string;
this_is_my_name_column: boolean;
suffix: string;
alias_name: AliasName[];
city: string;
country_now: string;
governorate: string;
zip_code: string;
location_text: string;
street_address: string;
date_living_address: string;
phone: PhoneNumber[];
email: string;
date_of_birth: string;
// Step2
education_information: EducationInformation[];
// Step3
employment_history: EmploymentHistory[];
// Step4
professional_qualification: ProfessionalQualification[];
// Step6
other_languages: string[];
electronic_signature: string;
full_name: string;
email_address: string;
i_agree_to_the_electronic_signature: boolean;
i_acknowledge_the_above: boolean; // إضافة هذا الحقل
}
// واجهة UpdateFields: لتمثيل الحقول المحدثة
export interface UpdateFields {
[key: string]: any;
}
export type FormData = {
home: HomeData &
Step1Data &
Step2Data &
Step3Data &
Step4Data &
Step6Data;
}; ```
// src/data/types.ts
// واجهة لحقل النموذج
export interface FormField<T = any> {
value: T;
isValid: boolean;
validationMessage: string;
touched?: boolean;
}
// واجهات البيانات لكل خطوة
export interface HomeData {
country: FormField<string>;
mobile_number: FormField<string>;
is_degree_or_diploma: FormField<boolean>;
from_time: FormField<string>;
to_time: FormField<string>;
}
export interface PhoneNumber {
id: string;
phone: string;
}
export interface AliasName {
id: string;
first_name: string;
last_name: string;
middle_name: string;
}
export interface Step1Data {
employer_name: FormField<string>;
first_name: FormField<string>;
last_name: FormField<string>;
dont_middle_name: FormField<boolean>;
middle_name: FormField<string>;
this_is_my_name_column: FormField<boolean>;
suffix: FormField<string>;
alias_name: AliasName[]; // قائمة أسماء المستعارة
country_now: FormField<string>;
city: FormField<string>;
governorate: FormField<string>;
zip_code: FormField<string>;
location_text: FormField<string>;
street_address: FormField<string>;
date_living_address: FormField<string>;
phone: PhoneNumber[]; // قائمة أرقام الهاتف
email: FormField<string>;
date_of_birth: FormField<string>;
}
export interface EducationInformation {
id: string;
name_of_school_or_college_university: string;
country: string;
city: string;
governorate: string;
location_text: string;
from_date: string;
to_date: string;
field_of_study_or_major: string;
phone: string;
ext: string;
diploma: string;
another_name: string;
}
export interface EmploymentHistory {
id: string;
company: string;
name_of_your_employer: string;
contact_the_employer: boolean;
issuing_salary: boolean;
country: string;
city: string;
governorate: string;
location_text: string;
continuous: boolean;
activity_has_stopped: boolean;
from_date: string;
end_date: string;
phone: string;
ext: string;
official_job_title_held_currently: string;
type_of_employment: string;
the_company_has_different_names: boolean;
different_company_names: string;
you_have_a_nicknamecx: boolean;
nickname: string;
file: File | string | null; // دعم كائن File أو رابط الملف (string)
}
export interface ProfessionalQualification {
id: string;
awarding_body: string;
license_or_certificate_number: string;
issuing_country: string;
date_awarded: string;
expiration_date?: string; // اختياري
award_name_description: string;
is_an_expiration_date: boolean;
your_name_varies: boolean;
}
export interface Step2Data {
educationInformation: EducationInformation[];
}
export interface Step3Data {
employment_history: EmploymentHistory[];
}
export interface Step4Data {
professional_qualification: ProfessionalQualification[];
}
export interface Step6Data {
other_languages: FormField<string[]>; // تصحيح النوع إلى string[]
electronic_signature: FormField<string>;
full_name: FormField<string>;
email_address: FormField<string>;
i_agree_to_the_electronic_signature: FormField<boolean>;
i_acknowledge_the_above: FormField<boolean>; // إضافة هذا الحقل
}
export interface ValidationResult {
[key: string]: {
isValid: boolean;
validationMessage?: string;
};
}
// واجهة RequestData: تمثل مجموعة كافة البيانات من الخطوات (للإرسال إلى الخادم)
export interface RequestData {
name: string;
user_id: string;
// Home
country: string;
mobile_number: string;
is_degree_or_diploma: boolean;
from_time: string;
to_time: string;
// Step1
employer_name: string;
first_name: string;
last_name: string;
dont_middle_name: boolean;
middle_name: string;
this_is_my_name_column: boolean;
suffix: string;
alias_name: AliasName[];
city: string;
country_now: string;
governorate: string;
zip_code: string;
location_text: string;
street_address: string;
date_living_address: string;
phone: PhoneNumber[];
email: string;
date_of_birth: string;
// Step2
education_information: EducationInformation[];
// Step3
employment_history: EmploymentHistory[];
// Step4
professional_qualification: ProfessionalQualification[];
// Step6
other_languages: string[];
electronic_signature: string;
full_name: string;
email_address: string;
i_agree_to_the_electronic_signature: boolean;
i_acknowledge_the_above: boolean; // إضافة هذا الحقل
}
// واجهة UpdateFields: لتمثيل الحقول المحدثة
export interface UpdateFields {
[key: string]: any;
}
export type FormData = {
home: HomeData &
Step1Data &
Step2Data &
Step3Data &
Step4Data &
Step6Data;
};
ملاحظات حول التعديلات:
التعامل مع أسماء المستعارة : تمت إضافة واجهة AliasName إلى البيانات المهيكلة، حيث تحتوي على الحقول first_name، last_name، وmiddle_name.
التعامل مع أرقام الهاتف : تمت إضافة واجهة PhoneNumber لتحكم في البيانات المتعلقة بأرقام الهاتف الخاصة بالمستخدم.
التأكد من سلامة البيانات : كما تم التأكيد على أن جميع الأنواع المستخدمة تتوافق مع المتطلبات السابقة.
إذا كان لديك أي استفسارات أو تحتاج إلى مزيد من التعديلات، فلا تتردد في إخباري!
<template>
<div class="pt-3 container">
<h1 class="text-3xl font-bold mb-3 text-black">Personal Information</h1>
<ul>
<li>All fields marked with an asterisk ( * ) are required.</li>
<li>Providing your information as completely and accurately as possible will help speed up the completion of your Background Verification</li>
</ul>
<div class="lg:grid grid-rows-2 lg:gap-2">
<h1 class="text-lg font-medium mb-1 mt-4 text-black">Name</h1>
<Info
text="Please provide your name exactly as it appears on your current government-issued identification document such as your Passport, Driver’s License or National Identification Document"
/>
</div>
<div class="lg:grid grid-cols-2 lg:gap-2">
<FieldContainer>
<StyledInput
labelText="Employer Name"
:isMandatory="true"
infoText="Employer Name"
inputType="text"
v-model="employerName"
:isValid="store.step1.employer_name.isValid"
:validationMessage="store.step1.employer_name.validationMessage"
name="employer_name"
id="EmployerName"
/>
<SupportingText>Supporting text</SupportingText>
</FieldContainer>
<FieldContainer>
<StyledInput
labelText="First Name"
:isMandatory="true"
infoText="First Name"
inputType="text"
v-model="firstName"
:isValid="store.step1.first_name.isValid"
:validationMessage="store.step1.first_name.validationMessage"
name="first_name"
id="firstName"
/>
</FieldContainer>
</div>
<FieldContainer>
<CheckBox
name="dont_middle_name"
id="dont_middle_name"
v-model="dontMiddleName"
>
I certify that I do not have a Middle Name on my official identification document
</CheckBox>
</FieldContainer>
<div class="lg:grid grid-cols-2 lg:gap-2">
<FieldContainer v-if="!dontMiddleName">
<StyledInput
labelText="Middle Name"
inputType="text"
v-model="middleName"
:isValid="store.step1.middle_name.isValid"
:validationMessage="store.step1.middle_name.validationMessage"
name="middle_name"
id="MiddleName"
/>
</FieldContainer>
</div>
<div class="lg:grid grid-cols-2 lg:gap-2">
<FieldContainer>
<StyledInput
labelText="Last Name"
:isMandatory="true"
infoText="Last Name"
inputType="text"
v-model="lastName"
:isValid="store.step1.last_name.isValid"
:validationMessage="store.step1.last_name.validationMessage"
name="last_name"
id="lastName"
/>
</FieldContainer>
<FieldContainer>
<Autocomp
id="suffix"
name="suffix"
labelText="Suffix"
infoText="Select your suffix"
inputType="text"
:options="suffixOptions"
@input-change="handleSuffix"
v-model="suffix"
:isValid="store.step1.suffix.isValid"
:validationMessage="store.step1.suffix.validationMessage"
/>
</FieldContainer>
</div>
<div class="lg:grid grid-cols-2 lg:gap-2">
<FieldContainer>
<Autocomp
name="country_now"
id="country"
labelText="Country"
infoText="Select your country"
inputType="text"
:options="optionCountry"
@input-change="handleCountryChange"
v-model="country"
:isValid="store.step1.country_now.isValid"
:validationMessage="store.step1.country_now.validationMessage"
/>
</FieldContainer>
<FieldContainer>
<Textarea
id="street_address"
name="street_address"
labelText="Street Address"
labelColor="blue"
infoText="Street Address"
size="xl"
v-model="streetAddress"
:isValid="store.step1.street_address.isValid"
:validationMessage="store.step1.street_address.validationMessage"
/>
</FieldContainer>
<FieldContainer>
<Autocomp
name="city"
id="city"
labelText="City"
infoText="City"
inputType="text"
:options="optionCity"
@input-change="handleCityChange"
v-model="city"
:isValid="store.step1.city.isValid"
:validationMessage="store.step1.city.validationMessage"
/>
</FieldContainer>
<FieldContainer>
<Autocomp
name="governorate"
id="governorate"
labelText="Governorate"
infoText="Governorate"
inputType="text"
:options="optionGovernorate"
@input-change="handleGovernorateChange"
v-model="governorate"
:isValid="store.step1.governorate.isValid"
:validationMessage="store.step1.governorate.validationMessage"
/>
</FieldContainer>
<FieldContainer>
<StyledInput
labelText="Location Text"
:isMandatory="true"
infoText="Location Text"
inputType="text"
v-model="locationText"
:isValid="store.step1.location_text.isValid"
:validationMessage="store.step1.location_text.validationMessage"
name="location_text"
id="locationText"
/>
</FieldContainer>
<FieldContainer>
<StyledInput
labelText="Zip Code"
:isMandatory="true"
infoText="Zip Code"
inputType="text"
v-model="zipCode"
:isValid="store.step1.zip_code.isValid"
:validationMessage="store.step1.zip_code.validationMessage"
name="zip_code"
id="zipCode"
/>
</FieldContainer>
<FieldContainer>
<StyledInput
id="date_living_address"
name="date_living_address"
labelText="Date you started living at this address"
:isMandatory="true"
infoText="End date of your education."
inputType="date"
v-model="dateLivingAddress"
:isValid="store.step1.zip_code.isValid"
:validationMessage="store.step1.zip_code.validationMessage"
/>
</FieldContainer>
</div>
<FieldContainer>
<CheckBox
name="this_is_my_name_column"
id="this_is_my_name_column"
v-model="thisIsMyNameColumn"
>
I certify this is my current legal name, exactly as it is displayed on my government-issued identification document *
</CheckBox>
</FieldContainer>
<div class="lg:grid grid-rows-2 lg:gap-2">
<h1 class="text-lg font-medium text-black">Alias Name</h1>
<Info
text="Skip this section if you do not have any alias names.
Please provide:
Any other names appearing on government-issued identity documents where that name differs from your primary identity document; or
A prior legal name which can include your birth surname or any official change to a legal name; or
A name that you use in an “official” capacity."
/>
</div>
<!-- إضافة قسم Alias Name -->
<div class="lg:grid grid-cols-1 lg:gap-2">
<h1 class="text-lg font-medium mb-1 mt-4 text-black">Alias Name</h1>
<Info text="Please provide your alias name." />
<!-- جدول فرعي لAlias Name -->
<div v-for="(alias, index) in aliasNames" :key="alias.id" class="flex items-center mb-2">
<FieldContainer>
<StyledInput
labelText="Full Name"
inputType="text"
v-model="aliasNames[index].first_name"
:isValid="true"
:validationMessage="''"
name="first_name"
:id="aliasNames[index].id"
@input="updateAliasName(index, aliasNames[index])"
/>
</FieldContainer>
<FieldContainer>
<StyledInput
labelText="Middle Name"
inputType="text"
v-model="aliasNames[index].middle_name"
:isValid="true"
:validationMessage="''"
name="middle_name"
:id="aliasNames[index].id"
@input="updateAliasName(index, aliasNames[index])"
/>
</FieldContainer>
<FieldContainer>
<StyledInput
labelText="Last Name"
inputType="text"
v-model="aliasNames[index].last_name"
:isValid="true"
:validationMessage="''"
name="last_name"
:id="aliasNames[index].id"
@input="updateAliasName(index, aliasNames[index])"
/>
</FieldContainer>
<!-- زر حذف Alias Name -->
<Button @click="removeAliasName(index)" class="ml-2 bg-red-500 hover:bg-red-700 text-white font-bold py-2 px-4 rounded">
Remove
</Button>
</div>
<!-- زر إضافة Alias Name جديد -->
<Button @click="addAliasName" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
Add Alias Name
</Button>
</div>
<div class="lg:grid grid-cols-1 lg:gap-2">
<FieldContainer>
<StyledInput
labelText="Email"
:isMandatory="true"
infoText="Please enter your email address"
inputType="email"
name="email"
id="email"
v-model="email"
:isValid="store.step1.email.isValid"
:validationMessage="store.step1.email.validationMessage"
/>
</FieldContainer>
<Info
text="Taakd may occasionally need to contact you for clarification of items on your Background Verification. We will never share or sell your email address."
/>
</div>
<!-- إضافة قسم أرقام الهواتف -->
<div class="lg:grid grid-cols-1 lg:gap-2">
<h1 class="text-lg font-medium mb-1 mt-4 text-black">Phone Numbers</h1>
<Info text="Please provide your phone numbers. You can add multiple phone numbers." />
<!-- جدول فرعي لأرقام الهواتف -->
<div v-for="(phone, index) in phoneNumbers" :key="index" class="flex items-center mb-2">
<FieldContainer>
<StyledInput
labelText="Phone"
inputType="text"
v-model="phoneNumbers[index].phone"
:isValid="true"
:validationMessage="''"
name="phone"
id="phone"
@input="updatePhoneNumber(index, phoneNumbers[index])"
/>
</FieldContainer>
<!-- زر حذف رقم الهاتف -->
<Button @click="removePhoneNumber(index)" class="ml-2 bg-red-500 hover:bg-red-700 text-white font-bold py-2 px-4 rounded">
Remove
</Button>
</div>
<!-- زر إضافة رقم هاتف جديد -->
<Button @click="addPhoneNumber" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
Add Phone Number
</Button>
</div>
<div class="lg:grid grid-ows-2 lg:gap-2">
<h1 class="text-lg font-medium text-black">Identification</h1>
<Info
text="Most public records are stored using your name and birth date, so providing this information allows us to accurately search these sources."
/>
</div>
<div class="lg:grid grid-cols-2 lg:gap-2">
<!-- Date of Birth -->
<FieldContainer>
<StyledInput
id="date_of_birth"
name="date_of_birth"
labelText="Date of Birth"
infoText="Start date of your education."
inputType="date"
v-model="dateOfBirth"
:isValid="store.step1.date_of_birth.isValid"
:validationMessage="store.step1.date_of_birth.validationMessage"
/>
</FieldContainer>
</div>
<div class="pt-5 flex w-full justify-center">
<Button level="other" @click="save" :disabled="loading" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
<span v-if="loading">جاري الحفظ...</span>
<span v-else>save -></span>
</Button>
</div>
</div>
</template>
<script setup lang="ts">
import { computed, ref } from 'vue';
import { useVerificationRequestStore } from '../../stores/verificationRequest';
import CheckBox from '../../components/checkBox.vue';
import FieldContainer from '../../components/fieldContainer.vue';
import StyledInput from '../../components/styledInput.vue';
import SupportingText from '../../components/supportingText.vue';
import Info from './components/info.vue';
import { useToast } from 'vue-toastification';
import Button from '../../components/button.vue';
import Autocomp from '../../components/autocomp.vue';
import Textarea from '../../components/textarea.vue';
import { useLocation } from '../../stores/locations';
import { v4 as uuidv4 } from 'uuid';
const store = useVerificationRequestStore();
const toast = useToast();
const locations = useLocation();
const location = locations.getLocation();
const loading = ref(false);
const phoneNumbers = ref([{ phone: '' }]);
const aliasNames = ref([{ id: uuidv4(), first_name: '', last_name: '', middle_name: '' }]);
const suffixOptions = [
{ label: 'Jr.', value: 'Jr.' },
{ label: 'Sr.', value: 'Sr.' },
{ label: 'III', value: 'III' },
{ label: 'PhD', value: 'PhD' },
{ label: 'MD', value: 'MD' },
{ label: 'Esq.', value: 'Esq.' },
];
const optionCountry = computed(() => {
if (location && location.data) {
return location.data
.filter((loc) => loc.location_type === 'Country')
.map((loc) => ({
label: loc.location_name,
value: loc.location_name,
}));
}
return [];
});
const optionCity = computed(() => {
if (location && location.data && country.value) {
return location.data
.filter(loc => loc.location_type === 'City' && loc.parent_location === country.value)
.map(loc => ({
label: loc.location_name,
value: loc.location_name,
}));
}
return [];
});
const optionGovernorate = computed(() => {
if (location && location.data && city.value) {
return location.data
.filter(loc => loc.location_type === 'Governorate' && loc.parent_location === city.value)
.map(loc => ({
label: loc.location_name,
value: loc.location_name,
}));
}
return [];
});
const employerName = computed({
get: () => store.step1.employer_name.value,
set: (val: string) => store.updateStep1('employer_name', { value: val }),
});
const firstName = computed({
get: () => store.step1.first_name.value,
set: (val: string) => store.updateStep1('first_name', { value: val }),
});
const lastName = computed({
get: () => store.step1.last_name.value,
set: (val: string) => store.updateStep1('last_name', { value: val }),
});
const dontMiddleName = computed({
get: () => store.step1.dont_middle_name.value,
set: (val: boolean) => store.updateStep1('dont_middle_name', { value: val }),
});
const middleName = computed({
get: () => store.step1.middle_name.value,
set: (val: string) => store.updateStep1('middle_name', { value: val }),
});
const thisIsMyNameColumn = computed({
get: () => store.step1.this_is_my_name_column.value,
set: (val: boolean) => store.updateStep1('this_is_my_name_column', { value: val }),
});
const suffix = computed({
get: () => store.step1.suffix.value,
set: (val: string) => store.updateStep1('suffix', { value: val }),
});
const country = computed({
get: () => store.step1.country_now.value,
set: (val: string) => store.updateStep1('country_now', { value: val }),
});
const governorate = computed({
get: () => store.step1.governorate.value,
set: (val: string) => store.updateStep1('governorate', { value: val }),
});
const city = computed({
get: () => store.step1.city.value,
set: (val: string) => store.updateStep1('city', { value: val }),
});
const locationText = computed({
get: () => store.step1.location_text.value,
set: (val: string) => store.updateStep1('location_text', { value: val }),
});
const streetAddress = computed({
get: () => store.step1.street_address.value,
set: (val: string) => store.updateStep1('street_address', { value: val }),
});
const zipCode = computed({
get: () => store.step1.zip_code.value,
set: (val: string) => store.updateStep1('zip_code', { value: val }),
});
const dateLivingAddress = computed({
get: () => store.step1.date_living_address.value,
set: (val: string) => store.updateStep1('date_living_address', { value: val }),
});
const email = computed({
get: () => store.step1.email.value,
set: (val: string) => store.updateStep1('email', { value: val }),
});
const dateOfBirth = computed({
get: () => store.step1.date_of_birth.value,
set: (val: string) => store.updateStep1('date_of_birth', { value: val }),
});
//Funciones for handling user inputs
const addPhoneNumber = () => {
phoneNumbers.value.push({ id: uuidv4(), phone: '' });
};
const removePhoneNumber = (index) => {
phoneNumbers.value.splice(index, 1);
};
const updatePhoneNumber = (index, value) => {
store.updatePhoneNumber(index, value);
};
const addAliasName = () => {
aliasNames.value.push({ id: uuidv4(), first_name: '', last_name: '', middle_name: '' });
};
const removeAliasName = (index) => {
aliasNames.value.splice(index, 1);
};
const updateAliasName = (index, alias) => {
store.updateAliasName(index, alias);
};
const save = async () => {
try {
loading.value = true;
await store.saveStep1();
} catch (error) {
const toast = useToast();
toast.error("حدث خطأ أثناء الحفظ.");
} finally {
loading.value = false;
}
};
</script>
<style scoped>
/* أضف تنسيقات إضافية إذا لزم الأمر */
</style>
2. ملف verificationRequest.ts typescript Copy code
// src/stores/verificationRequest.ts
import { defineStore } from 'pinia';
import {
HomeData,
Step1Data,
Step2Data,
Step3Data,
Step4Data,
Step6Data,
RequestData,
ValidationResult,
UpdateFields,
} from '../data/types';
import { createDocumentResource } from 'frappe-ui';
import { useToast } from 'vue-toastification';
import axios from 'axios';
interface StepValidation {
validation: ValidationResult;
}
interface VerificationRequestStoreState {
documentName: string | null;
home: HomeData;
step1: Step1Data;
step2: Step2Data;
step3: Step3Data;
step4: Step4Data;
step6: Step6Data;
validations: StepValidation[];
}
const getDefaultState = (): VerificationRequestStoreState => ({
documentName: null,
home: {
country: { value: '', isValid: false, validationMessage: '' },
mobile_number: { value: '', isValid: false, validationMessage: '' },
is_degree_or_diploma: { value: false, isValid: false, validationMessage: '' },
from_time: { value: '', isValid: false, validationMessage: '' },
to_time: { value: '', isValid: false, validationMessage: '' },
},
step1: {
employer_name: { value: '', isValid: false, validationMessage: '' },
first_name: { value: '', isValid: false, validationMessage: '' },
last_name: { value: '', isValid: false, validationMessage: '' },
dont_middle_name: { value: false, isValid: false, validationMessage: '' },
middle_name: { value: '', isValid: true, validationMessage: '' },
this_is_my_name_column: { value: false, isValid: false, validationMessage: '' },
suffix: { value: '', isValid: true, validationMessage: '' },
alias_name: [], // أسماء المستعارة
country_now: { value: '', isValid: false, validationMessage: '' },
city: { value: '', isValid: false, validationMessage: '' },
governorate: { value: '', isValid: false, validationMessage: '' },
zip_code: { value: '', isValid: false, validationMessage: '' },
location_text: { value: '', isValid: false, validationMessage: '' },
street_address: { value: '', isValid: false, validationMessage: '' },
date_living_address: { value: '', isValid: false, validationMessage: '' },
phone: [], // أرقام الهاتف
email: { value: '', isValid: false, validationMessage: '' },
date_of_birth: { value: '', isValid: false, validationMessage: '' },
},
step2: {
educationInformation: [],
},
step3: {
employment_history: [],
},
step4: {
professional_qualification: [],
},
step6: {
other_languages: { value: [] as string[], isValid: true, validationMessage: '' },
electronic_signature: { value: '', isValid: false, validationMessage: '' },
full_name: { value: '', isValid: false, validationMessage: '' },
email_address: { value: '', isValid: false, validationMessage: '' },
i_agree_to_the_electronic_signature: { value: false, isValid: false, validationMessage: '' },
i_acknowledge_the_above: { value: false, isValid: false, validationMessage: '' },
},
validations: Array.from({ length: 5 }, () => ({ validation: {} })),
});
export const useVerificationRequestStore = defineStore('verificationRequest', {
state: (): VerificationRequestStoreState => getDefaultState(),
actions: {
setDocumentName(name: string) {
this.documentName = name;
},
async loadDocument() {
const toast = useToast();
try {
await this.loadHomeFields();
await this.loadStep1Fields();
await this.loadStep2Fields();
await this.loadStep3Fields();
await this.loadStep4Fields();
await this.loadStep6Fields();
} catch (error) {
console.error("Error loading document:", error);
toast.error("حدث خطأ أثناء تحميل الوثيقة.");
}
},
updateHome<K extends keyof VerificationRequestStoreState['home']>(
field: K,
payload: Partial<VerificationRequestStoreState['home'][K]>
) {
this.home[field] = { ...this.home[field], ...payload };
},
updateStep1<K extends keyof VerificationRequestStoreState['step1']>(
field: K,
payload: Partial<VerificationRequestStoreState['step1'][K]>
) {
this.step1[field] = { ...this.step1[field], ...payload };
},
updateStep2<K extends keyof VerificationRequestStoreState['step2']>(
field: K,
payload: Partial<VerificationRequestStoreState['step2'][K]>
) {
this.step2[field] = { ...this.step2[field], ...payload };
},
updateStep3<K extends keyof VerificationRequestStoreState['step3']>(
field: K,
payload: Partial<VerificationRequestStoreState['step3'][K]>
) {
this.step3[field] = { ...this.step3[field], ...payload };
},
updateStep4<K extends keyof VerificationRequestStoreState['step4']>(
field: K,
payload: Partial<VerificationRequestStoreState['step4'][K]>
) {
this.step4[field] = { ...this.step4[field], ...payload };
},
updateStep6<K extends keyof VerificationRequestStoreState['step6']>(
field: K,
payload: Partial<VerificationRequestStoreState['step6'][K]>
) {
this.step6[field] = { ...this.step6[field], ...payload };
},
resetStore() {
Object.assign(this, getDefaultState());
},
addPhoneNumber() {
this.step1.phone.push({ id: `${Date.now()}`, phone: '' });
},
removePhoneNumber(index: number) {
this.step1.phone.splice(index, 1);
},
updatePhoneNumber(index: number, value: string) {
this.step1.phone[index].phone = value;
},
validatePhoneNumbers(): boolean {
let isValid = true;
this.step1.phone.forEach((phone, index) => {
if (!phone.phone || phone.phone.trim() === '') {
isValid = false;
this.step1.phone[index].isValid = false;
} else {
this.step1.phone[index].isValid = true;
}
});
return isValid;
},
updateAliasName(index: number, value: { first_name: string; last_name: string; middle_name: string }) {
this.step1.alias_name[index] = value;
},
async updateDocumentFields(updatedFields: UpdateFields) {
const toast = useToast();
if (!this.documentName) {
toast.error("لم يتم العثور على اسم الوثيقة. يرجى إنشاء وثيقة أولاً.");
return;
}
try {
const request = createDocumentResource({
doctype: 'Verification Instructions Request',
name: this.documentName,
});
await request.setValue.submit(updatedFields);
toast.success("تم تحديث الوثيقة بنجاح.");
} catch (error) {
console.error("Error updating document fields:", error);
toast.error("حدث خطأ أثناء تحديث الوثيقة.");
throw new Error('Error updating document fields');
}
},
validateStep1(): boolean {
let isValid = true;
const requiredFields: (keyof Step1Data)[] = [
'employer_name',
'first_name',
'last_name',
'country_now',
'city',
'governorate',
'zip_code',
'location_text',
'date_living_address',
'email',
'date_of_birth',
];
requiredFields.forEach((field) => {
const fieldData = this.step1[field];
if (!fieldData.value || (Array.isArray(fieldData.value) && fieldData.value.length === 0)) {
this.updateStep1(field, {
isValid: false,
validationMessage: 'هذا الحقل مطلوب.',
});
isValid = false;
} else {
this.updateStep1(field, {
isValid: true,
validationMessage: '',
});
}
});
const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (this.step1.email.value && !emailPattern.test(this.step1.email.value)) {
this.updateStep1('email', {
isValid: false,
validationMessage: 'يرجى إدخال بريد إلكتروني صحيح.',
});
isValid = false;
} else if (this.step1.email.value) {
this.updateStep1('email', {
isValid: true,
validationMessage: '',
});
}
return isValid;
},
async saveStep1() {
const toast = useToast();
if (!this.validateStep1()) {
toast.error('يرجى تصحيح الأخطاء قبل الحفظ.');
throw new Error('Validation failed');
}
const dataToSubmit: UpdateFields = {};
for (const key in this.step1) {
if (Object.prototype.hasOwnProperty.call(this.step1, key)) {
const field = key as keyof Step1Data;
dataToSubmit[key] = this.step1[field].value;
}
}
try {
await this.updateDocumentFields(dataToSubmit);
toast.success('تم حفظ البيانات بنجاح.');
} catch (error) {
throw error;
}
},
async loadHomeFields() {
try {
const request = createDocumentResource({
doctype: 'Verification Instructions Request',
name: this.documentName,
});
const data = await request.reload();
// تحديث الحقول في Home
this.updateHome('country', { value: data.country });
this.updateHome('mobile_number', { value: data.mobile_number });
this.updateHome('is_degree_or_diploma', { value: data.is_degree_or_diploma });
this.updateHome('from_time', { value: data.from_time });
this.updateHome('to_time', { value: data.to_time });
} catch (error) {
console.error("Error loading Home fields:", error);
const toast = useToast();
toast.error("حدث خطأ أثناء تحميل بيانات الحقول الرئيسية.");
}
},
async loadStep1Fields() {
try {
const request = createDocumentResource({
doctype: 'Verification Instructions Request',
name: this.documentName,
});
const data = await request.reload();
this.updateStep1('employer_name', { value: data.employer_name });
this.updateStep1('first_name', { value: data.first_name });
this.updateStep1('last_name', { value: data.last_name });
this.updateStep1('dont_middle_name', { value: data.dont_middle_name });
this.updateStep1('middle_name', { value: data.middle_name });
this.updateStep1('this_is_my_name_column', { value: data.this_is_my_name_column });
this.updateStep1('suffix', { value: data.suffix });
this.updateStep1('country_now', { value: data.country_now });
this.updateStep1('city', { value: data.city });
this.updateStep1('governorate', { value: data.governorate });
this.updateStep1('zip_code', { value: data.zip_code });
this.updateStep1('location_text', { value: data.location_text });
this.updateStep1('street_address', { value: data.street_address });
this.updateStep1('date_living_address', { value: data.date_living_address });
this.updateStep1('email', { value: data.email });
this.updateStep1('date_of_birth', { value: data.date_of_birth });
// تحميل الحقول الفرعية مثل alias_name و phone إذا كانت موجودة
if (data.alias_name && Array.isArray(data.alias_name)) {
this.step1.alias_name = data.alias_name;
}
if (data.phone && Array.isArray(data.phone)) {
this.step1.phone = data.phone;
}
} catch (error) {
console.error("Error loading Step1 fields:", error);
const toast = useToast();
toast.error("حدث خطأ أثناء تحميل بيانات الخطوة الأولى.");
}
},
async loadStep2Fields() {
try {
const request = createDocumentResource({
doctype: 'Verification Instructions Request',
name: this.documentName,
});
const data = await request.reload();
this.step2.educationInformation = data.education_information;
} catch (error) {
console.error("Error loading Step2 fields:", error);
const toast = useToast();
toast.error("حدث خطأ أثناء تحميل بيانات الخطوة الثانية.");
}
},
async loadStep3Fields() {
try {
const request = createDocumentResource({
doctype: 'Verification Instructions Request',
name: this.documentName,
});
const data = await request.reload();
this.step3.employment_history = data.employment_history;
} catch (error) {
console.error("Error loading Step3 fields:", error);
const toast = useToast();
toast.error("حدث خطأ أثناء تحميل بيانات الخطوة الثالثة.");
}
},
async loadStep4Fields() {
try {
const request = createDocumentResource({
doctype: 'Verification Instructions Request',
name: this.documentName,
});
const data = await request.reload();
this.step4.professional_qualification = data.professional_qualification;
} catch (error) {
console.error("Error loading Step4 fields:", error);
const toast = useToast();
toast.error("حدث خطأ أثناء تحميل بيانات الخطوة الرابعة.");
}
},
async loadStep6Fields() {
try {
const request = createDocumentResource({
doctype: 'Verification Instructions Request',
name: this.documentName,
});
const data = await request.reload();
this.updateStep6('other_languages', { value: data.other_languages });
this.updateStep6('electronic_signature', { value: data.electronic_signature });
this.updateStep6('full_name', { value: data.full_name });
this.updateStep6('email_address', { value: data.email_address });
this.updateStep6('i_agree_to_the_electronic_signature', { value: data.i_agree_to_the_electronic_signature });
this.updateStep6('acknowledge_electronic_signature', { value: data.acknowledge_electronic_signature });
this.updateStep6('i_acknowledge_the_above', { value: data.i_acknowledge_the_above });
} catch (error) {
console.error("Error loading Step6 fields:", error);
const toast = useToast();
toast.error("حدث خطأ أثناء تحميل بيانات الخطوة السادسة.");
}
},
},
});
3. ملف types.ts typescript Copy code
// src/data/types.ts
// واجهة لحقل النموذج
export interface FormField<T = any> {
value: T;
isValid: boolean;
validationMessage: string;
touched?: boolean;
}
// واجهات البيانات لكل خطوة
export interface HomeData {
country: FormField<string>;
mobile_number: FormField<string>;
is_degree_or_diploma: FormField<boolean>;
from_time: FormField<string>;
to_time: FormField<string>;
}
export interface PhoneNumber {
id: string; // معرف فريد لكل رقم هاتف
phone: string; // رقم الهاتف
}
export interface AliasName {
id: string; // معرف فريد لكل اسم مستعار
first_name: string; // الاسم الأول
last_name: string; // اسم العائلة
middle_name: string; // الاسم الأوسط
}
export interface Step1Data {
employer_name: FormField<string>;
first_name: FormField<string>;
last_name: FormField<string>;
dont_middle_name: FormField<boolean>;
middle_name: FormField<string>;
this_is_my_name_column: FormField<boolean>;
suffix: FormField<string>;
alias_name: AliasName[]; // قائمة أسماء المستعارة
country_now: FormField<string>;
city: FormField<string>;
governorate: FormField<string>;
zip_code: FormField<string>;
location_text: FormField<string>;
street_address: FormField<string>;
date_living_address: FormField<string>;
phone: PhoneNumber[]; // قائمة أرقام الهاتف
email: FormField<string>;
date_of_birth: FormField<string>;
}
export interface EducationInformation {
id: string;
name_of_school_or_college_university: string;
country: string;
city: string;
governorate: string;
location_text: string;
from_date: string;
to_date: string;
field_of_study_or_major: string;
phone: string;
ext: string;
diploma: string;
another_name: string;
}
export interface EmploymentHistory {
id: string;
company: string;
name_of_your_employer: string;
contact_the_employer: boolean;
issuing_salary: boolean;
country: string;
city: string;
governorate: string;
location_text: string;
continuous: boolean;
activity_has_stopped: boolean;
from_date: string;
end_date: string;
phone: string;
ext: string;
official_job_title_held_currently: string;
type_of_employment: string;
the_company_has_different_names: boolean;
different_company_names: string;
you_have_a_nicknamecx: boolean;
nickname: string;
file: File | string | null; // دعم كائن File أو رابط الملف (string)
}
export interface ProfessionalQualification {
id: string;
awarding_body: string;
license_or_certificate_number: string;
issuing_country: string;
date_awarded: string;
expiration_date?: string; // اختياري
award_name_description: string;
is_an_expiration_date: boolean;
your_name_varies: boolean;
}
export interface Step2Data {
educationInformation: EducationInformation[];
}
export interface Step3Data {
employment_history: EmploymentHistory[];
}
export interface Step4Data {
professional_qualification: ProfessionalQualification[];
}
export interface Step6Data {
other_languages: FormField<string[]>; // تصحيح النوع إلى string[]
electronic_signature: FormField<string>;
full_name: FormField<string>;
email_address: FormField<string>;
i_agree_to_the_electronic_signature: FormField<boolean>;
i_acknowledge_the_above: FormField<boolean>; // إضافة هذا الحقل
}
export interface ValidationResult {
[key: string]: {
isValid: boolean;
validationMessage?: string;
};
}
// واجهة RequestData: تمثل مجموعة كافة البيانات من الخطوات (للإرسال إلى الخادم)
export interface RequestData {
name: string;
user_id: string;
// Home
country: string;
mobile_number: string;
is_degree_or_diploma: boolean;
from_time: string;
to_time: string;
// Step1
employer_name: string;
first_name: string;
last_name: string;
dont_middle_name: boolean;
middle_name: string;
this_is_my_name_column: boolean;
suffix: string;
alias_name: AliasName[];
city: string;
country_now: string;
governorate: string;
zip_code: string;
location_text: string;
street_address: string;
date_living_address: string;
phone: PhoneNumber[];
email: string;
date_of_birth: string;
// Step2
education_information: EducationInformation[];
// Step3
employment_history: EmploymentHistory[];
// Step4
professional_qualification: ProfessionalQualification[];
// Step6
other_languages: string[];
electronic_signature: string;
full_name: string;
email_address: string;
i_agree_to_the_electronic_signature: boolean;
i_acknowledge_the_above: boolean; // إضافة هذا الحقل
}
// واجهة UpdateFields: لتمثيل الحقول المحدثة
export interface UpdateFields {
[key: string]: any;
}
export type FormData = {
home: HomeData &
Step1Data &
Step2Data &
Step3Data &
Step4Data &
Step6Data;
};
الملاحظات النهائية:
تم تضمين كل التحديثات المطلوبة في الملفات المذكورة.
يتم الآن معالجة أرقام الهواتف وأسماء المستعارة بشكل صحيح وتوضع ضمن الأنواع المخصصة.
يتم التحقق من صحة البيانات قبل إجراء أي عمليات حفظ.
إذا كان هناك المزيد من التعديلات التي تحتاجها أو أي استفسارات، فلا تتردد في إخباري!
typescript Copy code
async saveStep1() {
const toast = useToast();
// تحقق من صحة البيانات
if (!this.validateStep1()) {
toast.error('يرجى تصحيح الأخطاء قبل الحفظ.');
throw new Error('Validation failed');
}
const dataToSubmit: UpdateFields = {
alias_name: this.step1.alias_name,
phone: this.step1.phone, // تأكد من أن البيانات كانت مضافة بشكل صحيح
};
// إضافة باقي البيانات
this.updateDocumentFields(dataToSubmit)
.then(() => {
toast.success('تم حفظ البيانات بنجاح.');
})
.catch((error) => {
console.error('خطأ في حفظ البيانات:', error);
toast.error('حدث خطأ أثناء حفظ البيانات.');
});
}
ملخص
تأكد من أن بيانات alias_name وphone تضيف إلى كائن dataToSubmit قبل إرساله إلى قاعدة البيانات.
تأكد من أن الـ API الخاص بك في فريبي (Frappe) يتعامل مع الحقول الفرعية وسيتم حفظها بشكل صحيح.
إذا كنت بحاجة إلى مزيد من المساعدة في أي من هذه الخطوات، يرجى إبلاغي!
typescript Copy code
async saveStep1() {
const toast = useToast();
// تحقق من صلاحية البيانات
if (!this.validateStep1()) {
toast.error('يرجى تصحيح الأخطاء قبل الحفظ.');
throw new Error('Validation failed');
}
const dataToSubmit: UpdateFields = {
alias_name: this.step1.alias_name, // تضمين أسماء المستعارة
phone: this.step1.phone, // تضمين أرقام الهواتف
// إضافة باقي البيانات كما في السابق
};
for (const key in this.step1) {
if (Object.prototype.hasOwnProperty.call(this.step1, key)) {
const field = key as keyof Step1Data;
dataToSubmit[key] = this.step1[field].value;
}
}
try {
await this.updateDocumentFields(dataToSubmit);
toast.success('تم حفظ البيانات بنجاح.');
} catch (error) {
throw error;
}
}
4. تحميل البيانات إذا كنت تريد تحميل البيانات من Doctype، تأكد أيضًا من تحديث طريقة loadStep1Fields لتحميل alias_name:
typescript Copy code
async loadStep1Fields() {
try {
const request = createDocumentResource({
doctype: 'Verification Instructions Request',
name: this.documentName,
});
const data = await request.reload();
// تحديث الحقول في Step1
this.updateStep1('employer_name', { value: data.employer_name });
...
// تحميل الحقول الفرعية مثل alias_name و phone إذا كانت موجودة
if (data.alias_name && Array.isArray(data.alias_name)) {
this.step1.alias_name = data.alias_name;
}
if (data.phone && Array.isArray(data.phone)) {
this.step1.phone = data.phone;
}
} catch (error) {
console.error("Error loading Step1 fields:", error);
const toast = useToast();
toast.error("حدث خطأ أثناء تحميل بيانات الخطوة الأولى.");
}
}
الخلاصة بتطبيق هذه الخطوات، سيكون لديك الآن تعامل مع alias_name بشكل مشابه لـ education_information. سيوفر ذلك اتساقًا في كيفية إدارة البيانات عبر تطبيقك. إذا كان لديك أي استفسارات أو نقاط غير واضحة، فلا تتردد في طرحها!