feat: update EmployeeRequest validation rules to require join_date, base_salary, and employment_status only for non-owners; enhance EmployeeForm.vue to reflect required fields in the UI

This commit is contained in:
Yoga Pangestu 2026-06-19 21:13:03 +07:00
parent 34e6e88069
commit e55df2cd4f
2 changed files with 7 additions and 7 deletions

View File

@ -25,7 +25,7 @@ public function authorize(): bool
*/ */
public function rules(): array public function rules(): array
{ {
$anyEmployee = ! empty($this->join_date) || ! empty($this->employment_status) || ! empty($this->base_salary); $isOwner = $this->role === Role::OWNER->value;
return [ return [
'email' => ['required', 'email', 'max:100', Rule::unique('users', 'email')->ignore($this->route('user')?->id)], 'email' => ['required', 'email', 'max:100', Rule::unique('users', 'email')->ignore($this->route('user')?->id)],
@ -35,9 +35,9 @@ public function rules(): array
'gender' => ['nullable', Rule::enum(Gender::class)], 'gender' => ['nullable', Rule::enum(Gender::class)],
'birth_date' => ['nullable', 'date', 'before:today'], 'birth_date' => ['nullable', 'date', 'before:today'],
'address' => ['nullable', 'string'], 'address' => ['nullable', 'string'],
'join_date' => [$anyEmployee ? 'required' : 'nullable', 'date'], 'join_date' => [Rule::requiredIf(! $isOwner), 'date'],
'employment_status' => [$anyEmployee ? 'required' : 'nullable', Rule::enum(EmploymentStatus::class)], 'employment_status' => [Rule::requiredIf(! $isOwner), Rule::enum(EmploymentStatus::class)],
'base_salary' => [$anyEmployee ? 'required' : 'nullable', 'integer', 'min:0'], 'base_salary' => [Rule::requiredIf(! $isOwner), 'integer', 'min:0'],
'role' => ['required', Rule::in(Role::assignableValues())], 'role' => ['required', Rule::in(Role::assignableValues())],
]; ];
} }

View File

@ -181,18 +181,18 @@ function submit() {
<FieldGroup> <FieldGroup>
<FieldSet class=" grid gap-4 md:grid-cols-3"> <FieldSet class=" grid gap-4 md:grid-cols-3">
<Field> <Field>
<FieldLabel for="join_date">Tanggal Bergabung</FieldLabel> <FieldLabel for="join_date" required>Tanggal Bergabung</FieldLabel>
<DatePicker id="join_date" v-model="form.join_date" <DatePicker id="join_date" v-model="form.join_date"
placeholder="Pilih tanggal bergabung" /> placeholder="Pilih tanggal bergabung" />
<FieldError :errors="formErrors(form, 'join_date')" /> <FieldError :errors="formErrors(form, 'join_date')" />
</Field> </Field>
<Field> <Field>
<FieldLabel for="base_salary">Gaji Pokok</FieldLabel> <FieldLabel for="base_salary" required>Gaji Pokok</FieldLabel>
<RupiahInput id="base_salary" v-model="form.base_salary" /> <RupiahInput id="base_salary" v-model="form.base_salary" />
<FieldError :errors="formErrors(form, 'base_salary')" /> <FieldError :errors="formErrors(form, 'base_salary')" />
</Field> </Field>
<Field> <Field>
<FieldLabel for="employment_status">Status Kepegawaian</FieldLabel> <FieldLabel for="employment_status" required>Status Kepegawaian</FieldLabel>
<Select v-model="form.employment_status"> <Select v-model="form.employment_status">
<SelectTrigger id="employment_status" class="w-full"> <SelectTrigger id="employment_status" class="w-full">
<SelectValue placeholder="Pilih status kepegawaian" /> <SelectValue placeholder="Pilih status kepegawaian" />