create create page

This commit is contained in:
Marley Rae 2022-04-27 19:33:19 -07:00
parent 985febc962
commit 94557a817f
9 changed files with 128 additions and 5 deletions

View file

@ -25,6 +25,7 @@ public function index()
*/
public function create()
{
return view('admin.owned.create');
}
/**

View file

@ -2,6 +2,10 @@
define('PER_PAGE', 7);
define('DATE_FMT', 'j F Y');
define('FORM_DATE_FMT', 'Y-m-d');
define('DATE_FMT_SHORT', 'j M y');
/* ------------------------------------------------------------------------- auth_collective ---- */
// returns the currently authenticated collective

View file

@ -118,6 +118,7 @@ .form__label:first-child, .form__btns:first-child, .form__checkbox:first-child,
.form__input, .form__input--search, .form__select {
border: 1px solid #7874ff;
background-color: #e4e3ff;
width: 50%;
border-color: #7874ff;
background-color: #e4e3ff;
color: #7874ff;
@ -142,6 +143,7 @@ .form__input--file {
color: #7874ff;
transition: background-color 0.4s, border-color 0.4s, color 0.4s;
padding: 5px;
width: 50%;
}
.form__input--file:hover {
border-color: #de7cff;

View file

@ -57,6 +57,7 @@ h1 {
.form__input {
border: 1px solid $c-main;
background-color: $c-main-lightest;
width: 50%;
@include hover;
}
@ -69,6 +70,7 @@ h1 {
border: 1px solid $c-main;
@include hover($bg: false);
padding: 5px;
width: 50%;
&::file-selector-button {
@extend %btn;

View file

@ -0,0 +1,29 @@
@extends('admin.layout')
@section('pg-nav')
<x-admin.nav :section="'owned'" />
@endsection
@section('pg-title', 'Add Owned')
@section('content')
<form action="{{ route('admin.owned.store') }}" method="POST" autocomplete="off">
@csrf
<fieldset class="form__fieldset">
<x-admin.form.categories name="categories[]" required />
<x-form.text name="subject" :label="'Subject:'" required />
<x-form.select name="status" :label="'Status:'" :size="1" required />
<x-form.text name="slug" :label="'Slug:'" required />
<x-form.text name="title" :label="'Title:'" />
<x-form.file name="image" />
<x-form.date name="date_opened" :label="'Date opened:'" />
<x-form.checkbox name="hold_member_updates" :label="'Hold member updates?'" />
<x-form.checkbox name="notify_pending" :label="'Notify when you have pending members?'" />
<x-form.buttons />
</fieldset>
</form>
@endsection

View file

@ -1,4 +1,4 @@
{{-- expected attributes: name, id --}}
{{-- expected attributes: name --}}
@props([
'prevCats' => false,
'labelClass' => '',
@ -10,7 +10,7 @@
use App\Models\Category;
$categories = Category::all();
$id = rtrim($attributes['name'], '[]');
$id = $attributes['id'] ?? rtrim($attributes['name'], '[]');
$selected = null;
$name = rtrim($attributes['name'], '[]');

View file

@ -0,0 +1,16 @@
{{-- expected attributes: name --}}
@props([
'labelClass' => '',
'label',
'current' => null,
'inputClass' => '',
'errorClass' => '',
])
<label for="{{ $attributes['id'] ?? $attributes['name'] }}" class="form__label {{ $labelClass }}">
{{ $label }}
</label>
<input type="date" id="{{ $attributes['id'] ?? $attributes['name'] }}" {{ $attributes }}
value="{{ old($attributes['name'], $current?->format(FORM_DATE_FMT)) }}"
class="form__input {{ $inputClass }}">
@error($attributes['name']) <p class="form__error {{ $errorClass }}">{{ $message }}</p> @enderror

View file

@ -0,0 +1,48 @@
{{-- expected attributes: name --}}
@props([
'prevVals' => false,
'vals' => false,
'labelClass' => '',
'selectClass' => '',
'errorClass' => '',
'size' => 6,
'label',
])
@php
$id = $attributes['id'] ?? rtrim($attributes['name'], '[]');
$selected = null;
$name = rtrim($attributes['name'], '[]');
if (old($name) != null) {
$selected = collect(old($name));
} else if ($prevVals) {
$selected = collect($prevVals);
}
if (!$vals) {
switch ($name) {
case 'status':
$vals = ['upcoming', 'current'];
break;
default:
break;
}
}
@endphp
<label for="{{ $id }}" class="form__label {{ $labelClass }}">{{ $label }}</label>
<select id="{{ $id }}" {{ $attributes }} class="form__select {{ $selectClass }}" size="{{ $size }}">
@if (!isset($attributes['multiple']))
<option value=""></option>
@endif
@foreach ($vals as $val)
<option value="{{ $val }}"
@if(isset($selected)) @selected($selected->search($val) !== false) @endif>
{{ $val }}
</option>
@endforeach
</select>
@error($attributes['name']) <p class="form__error {{ $errorClass }}">{{ $message }}</p> @enderror

View file

@ -1,7 +1,28 @@
<?php
it('has owned/create page', function () {
$response = $this->get('/owned/create');
use App\Models\Collective;
use function Pest\Faker\faker;
$response->assertStatus(200);
uses()->group('owned', 'admin');
beforeEach(function () {
$this->user = Collective::first();
$this->request = [
'categories' => [rand(1, 57), rand(1, 57), rand(1, 57)],
'url' => faker()->url,
'subject' => faker()->word,
'approved' => faker()->boolean,
];
});
it('has owned create page', function () {
$response = $this->actingAs($this->user)->get('/fanatic/owned/create');
$response->assertViewIs('admin.owned.create');
});
it('hides owned create page from guests', function () {
$response = $this->get('/fanatic/owned/create');
$response->assertRedirect('/fanatic/login');
});