Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
marchershey committed Dec 22, 2024
1 parent 4adc1ee commit 09acb75
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 14 deletions.
111 changes: 111 additions & 0 deletions app/app/Forms/HostPropertyForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<?php

namespace App\Forms;

use Livewire\Attributes\Validate;
use Livewire\Form;

class HostPropertyForm extends Form
{
// Basic
#[Validate('required|string|max:250|unique:properties,name', as: 'property name')]
public ?string $name;

#[Validate('required|string|max:250', as: 'street address')]
public ?string $address_line1;

#[Validate('nullable|string|max:250', as: 'address line 2')]
public ?string $address_line2;

#[Validate('required|string|max:250', as: 'city')]
public ?string $address_city;

#[Validate('required|string|alpha|size:2', as: 'state')]
public ?string $address_state;

#[Validate('required|string|numeric|digits:5|regex:/^\d{5}$/', as: 'zip / postal code')]
public $address_postal = '';
// would love to make this "public ?int $address_postal" but... https://github.com/livewire/flux/issues/829

#[Validate('required|string|alpha|size:2', as: 'country')]
public ?string $address_country;

// Listing
#[Validate('required|string|max:250', as: 'headline')]
public ?string $listing_headline;

#[Validate('required|string|max:3000', as: 'description')]
public string $listing_description = '';

#[Validate('required|integer|numeric|min:1|max:16', as: 'guest count')]
public int $guest_count = 1;

#[Validate('required|integer|numeric|min:0|max:99', as: 'bed count')]
public int $bed_count = 0;

#[Validate('required|integer|numeric|min:0|max:99', as: 'bedroom count')]
public int $bedroom_count = 0;

#[Validate('required|decimal:0,1|numeric|min:0|max:99', as: 'bathroom count')]
public int $bathroom_count = 0;

#[Validate('required|integer|exists:App\Models\PropertyType,id', as: 'property type')]
public ?int $property_type;

// #[Validate('required|array', as: 'amenities')]
#[Validate([
'amenities' => 'required|array',
'amenities.*' => 'required',
], as: [
'amenities' => 'amenities',
'amenities.*' => 'amenity item',
], message: [
'amenities.required' => 'Amenities are required.',
])]
public array $amenities = [];

// Rates
#[Validate('required|numeric|min:1|max:1000|decimal:0,2', as: 'base rate')]
public int|string $base_rate = '';

#[Validate('required|numeric|min:0|max:99', as: 'tax rate')]
public int|string $tax_rate = '';

#[Validate([
'fees' => 'nullable|array:name,amount,type',
'fees.*.name' => 'required|string|max:250',
'fees.*.amount' => 'required|numeric|min:0|max:1000|decimal:0,2',
'fees.*.type' => 'required|in:fixed,variable',
], as: [
'fees.*.name' => 'fee name',
'fees.*.amount' => 'fee amount',
'fees.*.type' => 'fee type',
])]
public array $fees = [];

// Photos
#[Validate([
'photos' => 'required',
'photos.*' => 'required|image|mimes:jpg,jpeg,png,webp,bmp|extensions:jpg,jpeg,png,webp,bmp|max:10240',
], as: [
'photos.' => 'photos',
'photos.*' => 'photo',
])]
public array $photos = [];

// Options
#[Validate('required|string|max:250|unique:properties,slug|regex:^[a-z0-9]+(?:-[a-z0-9]+)*$', as: 'url', onUpdate: false)]
public ?string $slug;

#[Validate('required|integer|min:1|max:99', as: 'minimum nights')]
public int $duration_min = 1;

#[Validate('required|integer|min:1|max:99', as: 'maximum nights')]
public int $duration_max = 14;

#[Validate('required|string|in:private,unlisted,public', as: 'visibility')]
public ?string $visibility;

#[Validate('required|regex:/^#[0-9A-Fa-f]{6}$/', as: 'color')]
public string $calendar_color = '#2563eb';
}
3 changes: 2 additions & 1 deletion app/app/Models/Property.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

namespace App\Models;

use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Str;

class Property extends Model
{
use HasFactory;
use HasFactory, HasUuids;

/**
* Automatically generate a unique slug for the property.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ public function up(): void
$table->integer('address_postal');
$table->string('address_country');
// Listing
$table->integer('type_id');
$table->string('listing_headline');
$table->text('listing_description');
$table->integer('type_id');
$table->integer('guest_count');
$table->integer('bed_count');
$table->integer('bedroom_count');
Expand All @@ -33,11 +33,11 @@ public function up(): void
$table->integer('base_rate');
$table->integer('tax_rate');
// Options
$table->string('slug');
$table->string('calendar_color');
$table->integer('duration_min');
$table->integer('duration_max');
$table->string('visibility');
$table->string('slug');
$table->string('calendar_color');

$table->integer('host_id');
$table->timestamps();
Expand Down
20 changes: 12 additions & 8 deletions app/resources/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,15 @@ window.addEventListener("console", (event) => {
console.log(event.detail);
});

// window.addEventListener(
// "popstate",
// (event) => {
// // The popstate event is fired each time when the current history entry changes.
// location.reload();
// },
// false,
// );

/**
* https://github.com/marchershey/lodge-board-beta/issues/130
*/
window.addEventListener(
"popstate",
(event) => {
// The popstate event is fired each time when the current history entry changes.
location.reload();
},
false,
);
2 changes: 1 addition & 1 deletion app/resources/views/layouts/host.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
</div>

{{-- Content Container --}}
<div class="relative">
<div class="relative flex-1">
<div class="page-header sticky top-0 z-10">
<div class="page-x-padding container flex items-center justify-between">
<h1 class="page-title">{{ $pageTitle }}</h1>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
@endif

{{-- Amenities modal --}}
<flux:modal class="w-[90%] space-y-6 tablet:w-[500px]" name="amenities-modal">
<flux:modal class="max-h-[50rem] w-[90%] space-y-6" name="amenities-modal">
<div>
<flux:legend size="xl">Select amenities</flux:legend>
<flux:subheading>Select all of the amenities that your property includes</flux:subheading>
Expand Down

0 comments on commit 09acb75

Please sign in to comment.