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:
parent
34e6e88069
commit
e55df2cd4f
@ -25,7 +25,7 @@ public function authorize(): bool
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
$anyEmployee = ! empty($this->join_date) || ! empty($this->employment_status) || ! empty($this->base_salary);
|
||||
$isOwner = $this->role === Role::OWNER->value;
|
||||
|
||||
return [
|
||||
'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)],
|
||||
'birth_date' => ['nullable', 'date', 'before:today'],
|
||||
'address' => ['nullable', 'string'],
|
||||
'join_date' => [$anyEmployee ? 'required' : 'nullable', 'date'],
|
||||
'employment_status' => [$anyEmployee ? 'required' : 'nullable', Rule::enum(EmploymentStatus::class)],
|
||||
'base_salary' => [$anyEmployee ? 'required' : 'nullable', 'integer', 'min:0'],
|
||||
'join_date' => [Rule::requiredIf(! $isOwner), 'date'],
|
||||
'employment_status' => [Rule::requiredIf(! $isOwner), Rule::enum(EmploymentStatus::class)],
|
||||
'base_salary' => [Rule::requiredIf(! $isOwner), 'integer', 'min:0'],
|
||||
'role' => ['required', Rule::in(Role::assignableValues())],
|
||||
];
|
||||
}
|
||||
|
||||
@ -181,18 +181,18 @@ function submit() {
|
||||
<FieldGroup>
|
||||
<FieldSet class=" grid gap-4 md:grid-cols-3">
|
||||
<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"
|
||||
placeholder="Pilih tanggal bergabung" />
|
||||
<FieldError :errors="formErrors(form, 'join_date')" />
|
||||
</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" />
|
||||
<FieldError :errors="formErrors(form, 'base_salary')" />
|
||||
</Field>
|
||||
<Field>
|
||||
<FieldLabel for="employment_status">Status Kepegawaian</FieldLabel>
|
||||
<FieldLabel for="employment_status" required>Status Kepegawaian</FieldLabel>
|
||||
<Select v-model="form.employment_status">
|
||||
<SelectTrigger id="employment_status" class="w-full">
|
||||
<SelectValue placeholder="Pilih status kepegawaian" />
|
||||
|
||||
Loading…
Reference in New Issue
Block a user