diff --git a/resources/views/components/⚡contact-list.blade.php b/resources/views/components/⚡contact-list.blade.php new file mode 100644 index 0000000..15b1a7a --- /dev/null +++ b/resources/views/components/⚡contact-list.blade.php @@ -0,0 +1,89 @@ +sortBy === $column) { + $this->sortDirection = $this->sortDirection === 'asc' ? 'desc' : 'asc'; + } else { + $this->sortBy = $column; + $this->sortDirection = 'asc'; + } + } + + #[On('contact-created')] + #[On('contact-updated')] + public function refresh(): void {} + + #[Computed] + public function contacts() + { + return Contact::orderBy($this->sortBy, $this->sortDirection)->paginate(10); + } +}; +?> + + +
+ + + + First Name + + + Last Name + + + Email + + + Phone + + + Created + + + + + + @foreach($this->contacts as $contact) + + {{ $contact->first_name }} + {{ $contact->last_name }} + {{ $contact->email }} + {{ $contact->phone }} + {{ $contact->created_at->local()->format('m/d/Y | g:i A') }} + + + + + + + + Edit + + + + + + @endforeach + + +
\ No newline at end of file diff --git a/resources/views/components/⚡create-contact.blade.php b/resources/views/components/⚡create-contact.blade.php new file mode 100644 index 0000000..b195a4a --- /dev/null +++ b/resources/views/components/⚡create-contact.blade.php @@ -0,0 +1,61 @@ +validate(); + + Contact::create([ + 'first_name' => $this->first_name, + 'last_name' => $this->last_name, + 'email' => $this->email, + 'phone' => $this->phone ?: null, + ]); + + $this->reset(); + Flux::modal('create-contact')->close(); + $this->dispatch('contact-created'); + } +}; +?> + +
+ + + New Contact + + + + +
+ Create Contact + + + + + + +
+ + Create +
+ +
+
\ No newline at end of file diff --git a/resources/views/components/⚡edit-contact.blade.php b/resources/views/components/⚡edit-contact.blade.php new file mode 100644 index 0000000..637e58e --- /dev/null +++ b/resources/views/components/⚡edit-contact.blade.php @@ -0,0 +1,79 @@ +contactId = $contactId; + $contact = Contact::findOrFail($contactId); + + $this->first_name = $contact->first_name; + $this->last_name = $contact->last_name; + $this->email = $contact->email; + $this->phone = $contact->phone ?? ''; + + $this->resetValidation(); + Flux::modal('edit-contact')->show(); + } + + public function save(): void + { + $this->validate([ + 'first_name' => 'required|string|max:255', + 'last_name' => 'required|string|max:255', + 'email' => 'required|email|max:255|unique:contacts,email,' . $this->contactId, + 'phone' => 'nullable|string|max:20', + ]); + + $contact = Contact::findOrFail($this->contactId); + $contact->update([ + 'first_name' => $this->first_name, + 'last_name' => $this->last_name, + 'email' => $this->email, + 'phone' => $this->phone ?: null, + ]); + + $this->reset(); + Flux::modal('edit-contact')->close(); + $this->dispatch('contact-updated'); + } +}; +?> + +
+ +
+ Edit Contact + + + + + + +
+ + Save +
+ +
+
\ No newline at end of file diff --git a/resources/views/contacts/index.blade.php b/resources/views/contacts/index.blade.php index e69de29..4ae884d 100644 --- a/resources/views/contacts/index.blade.php +++ b/resources/views/contacts/index.blade.php @@ -0,0 +1,9 @@ + +
+
+ +
+ + +
+