Refactor card components. Choose school screen showing.
This commit is contained in:
parent
afcdd34532
commit
7ebc3a2dd4
|
|
@ -0,0 +1,30 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use function redirect;
|
||||||
|
|
||||||
|
class DashboardController extends Controller
|
||||||
|
{
|
||||||
|
public function profile()
|
||||||
|
{
|
||||||
|
return view('dashboard.profile');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function dashboard()
|
||||||
|
{
|
||||||
|
return view('dashboard.dashboard');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function my_school()
|
||||||
|
{
|
||||||
|
if (Auth::user()->school) {
|
||||||
|
return redirect('/schools/' . Auth::user()->school->id);
|
||||||
|
}
|
||||||
|
$possibilities = Auth::user()->possibleSchools();
|
||||||
|
if (count($possibilities) < 1) return view('schools.create');
|
||||||
|
return view('dashboard.select_school', ['possibilities' => $possibilities]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -20,4 +20,11 @@ class School extends Model
|
||||||
{
|
{
|
||||||
return $this->hasMany(SchoolEmailDomain::class);
|
return $this->hasMany(SchoolEmailDomain::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function initialLetterImageURL($bg_color = '4f46e5', $text_color='fff'): string
|
||||||
|
{
|
||||||
|
$img = "https://ui-avatars.com/api/?background=$bg_color&color=$text_color&name=";
|
||||||
|
$img .= substr($this->name,0,1);
|
||||||
|
return $img;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,16 @@ namespace App\Models;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
|
||||||
class SchoolEmailDomain extends Model
|
class SchoolEmailDomain extends Model
|
||||||
{
|
{
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
protected $guarded = [];
|
protected $guarded = [];
|
||||||
public $timestamps = false;
|
public $timestamps = false;
|
||||||
|
|
||||||
|
public function school(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(School::class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ namespace App\Models;
|
||||||
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
||||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||||
use Illuminate\Notifications\Notifiable;
|
use Illuminate\Notifications\Notifiable;
|
||||||
|
|
||||||
|
|
@ -67,4 +68,25 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||||
{
|
{
|
||||||
return $this->belongsTo(School::class);
|
return $this->belongsTo(School::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array of schools using the users email domiain
|
||||||
|
* @return SchoolEmailDomain[]
|
||||||
|
*/
|
||||||
|
public function possibleSchools()
|
||||||
|
{
|
||||||
|
if ($this->school_id) {
|
||||||
|
$return[] = $this->school;
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
|
return SchoolEmailDomain::with('school')->where('domain','=',$this->emailDomain())->get();
|
||||||
|
// $x = SchoolEmailDomain::with('school')->where('domain','=',Auth::user()->emailDomain())->get();
|
||||||
|
// $possibilities = SchoolEmailDomain::with('school')->where('domain','=', $this->emailDomain())->getModels();
|
||||||
|
// $return = [];
|
||||||
|
// foreach ($possibilities as $possibility) {
|
||||||
|
// $return[] = $possibility->school;
|
||||||
|
// }
|
||||||
|
// return $return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
@props(['heading' => false, 'subheading' => false])
|
||||||
|
<div class="overflow-hidden bg-white shadow sm:rounded-lg">
|
||||||
|
@if($heading)
|
||||||
|
<div class="px-4 py-6 sm:px-6 border-b border-gray-100"> <!-- HEADING -->
|
||||||
|
<h3 class="text-base font-semibold leading-7 text-gray-900">{{ $heading }}</h3>
|
||||||
|
@if($subheading)
|
||||||
|
<p class="mt-1 max-w-2xl text-sm leading-6 text-gray-500">{{ $subheading }}</p>
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
|
||||||
|
{{ $slot }}
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
<div class="border-t border-gray-100">
|
||||||
|
<dl class="divide-y divide-gray-100">
|
||||||
|
{{ $slot }}
|
||||||
|
</dl>
|
||||||
|
</div>
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
@props(['view_all_href' => false])
|
||||||
|
<div>
|
||||||
|
<ul role="list" class="divide-y divide-gray-100 ">
|
||||||
|
{{ $slot }}
|
||||||
|
</ul>
|
||||||
|
@if($view_all_href)
|
||||||
|
<a href="{{ $view_all_href }}" class="flex w-full items-center justify-center rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50 focus-visible:outline-offset-0">View all</a>
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
@php
|
||||||
|
$img_classes = "h-12 w-12 flex-none rounded-full bg-gray-50";
|
||||||
|
@endphp
|
||||||
|
<img {{ $attributes->merge(['class' => $img_classes]) }}>
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
<div class="min-w-0 flex-auto">
|
||||||
|
<p class="text-sm font-semibold leading-6 text-gray-900">{{ $slot }}</p>
|
||||||
|
@if(isset($subtext))
|
||||||
|
<p class="mt-1 truncate text-xs leading-5 text-gray-500">{{ $subtext }}</p>
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
<li class="flex items-center justify-between gap-x-6 px-4 py-5 sm:px-6">
|
||||||
|
<div class="flex min-w-0 gap-x-4">
|
||||||
|
{{ $slot }}
|
||||||
|
</div>
|
||||||
|
@if(isset($right_link_button))
|
||||||
|
<a {{ $right_link_button->attributes->merge(['class' => 'rounded-full bg-white px-2.5 py-1 text-xs font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50']) }}>
|
||||||
|
{{ $right_link_button }}
|
||||||
|
</a>
|
||||||
|
@endif
|
||||||
|
</li>
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
@props(['heading' => false, 'subheading' => false])
|
|
||||||
<div class="overflow-hidden bg-white shadow sm:rounded-lg">
|
|
||||||
@if($heading)
|
|
||||||
@include('components.info-card.header', ['heading' => $heading, 'subheading' => $subheading])
|
|
||||||
@endif
|
|
||||||
|
|
||||||
<div class="border-t border-gray-100">
|
|
||||||
<dl class="divide-y divide-gray-100">
|
|
||||||
{{ $slot }}
|
|
||||||
</dl>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
<div class="px-4 py-6 sm:px-6"> <!-- HEADING -->
|
|
||||||
<h3 class="text-base font-semibold leading-7 text-gray-900">{{ $heading }}</h3>
|
|
||||||
@if($subheading)
|
|
||||||
<p class="mt-1 max-w-2xl text-sm leading-6 text-gray-500">{{ $subheading }}</p>
|
|
||||||
@endif
|
|
||||||
</div>
|
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
@php use Illuminate\Support\Facades\Auth; @endphp
|
||||||
|
@php $school = Auth::user()->school; @endphp
|
||||||
|
<x-layout.app>
|
||||||
|
<x-slot:page_title>Choose School</x-slot:page_title>
|
||||||
|
|
||||||
|
<x-card.card heading="Choose your school"
|
||||||
|
subheading="Based on your email address, one of these schools may be yours">
|
||||||
|
<x-card.list.body>
|
||||||
|
@foreach($possibilities as $possibility)
|
||||||
|
@php $school = $possibility->school; @endphp
|
||||||
|
<x-card.list.row>
|
||||||
|
<x-card.list.row-image
|
||||||
|
src="{{ $school->initialLetterImageURL() }}"
|
||||||
|
alt=""/>
|
||||||
|
<x-card.list.row-text-subtext>
|
||||||
|
{{ $school->name }}
|
||||||
|
<x-slot:subtext>{{ $school->city }}, {{ $school->state }}</x-slot:subtext>
|
||||||
|
</x-card.list.row-text-subtext>
|
||||||
|
</x-card.list.row>
|
||||||
|
@endforeach
|
||||||
|
</x-card.list.body>
|
||||||
|
</x-card.card>
|
||||||
|
</x-layout.app>
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
@php use Illuminate\Support\Facades\Auth; @endphp
|
|
||||||
@php $school = Auth::user()->school; @endphp
|
|
||||||
<x-layout.app>
|
|
||||||
<x-slot:page_title>My School</x-slot:page_title>
|
|
||||||
<div class="space-y-10 divide-y divide-gray-900/10">
|
|
||||||
|
|
||||||
@if($school)
|
|
||||||
<a href="/schools/{{ $school->id }}/edit">Edit my school</a>
|
|
||||||
@endif
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</x-layout.app>
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
<x-layout.app>
|
<x-layout.app>
|
||||||
<x-slot:page_title>School Info - {{ $school->name }}</x-slot:page_title>
|
<x-slot:page_title>School Info - {{ $school->name }}</x-slot:page_title>
|
||||||
|
|
||||||
<x-info-card.card>
|
<x-card.card>
|
||||||
<x-info-card.row row_name="School Address">
|
<x-card.info.body>
|
||||||
|
<x-card.info.row row_name="School Address">
|
||||||
<div class="md:grid md:grid-cols-3">
|
<div class="md:grid md:grid-cols-3">
|
||||||
<div class="md:col-span-2">
|
<div class="md:col-span-2">
|
||||||
{{ $school->name }}<br />
|
{{ $school->name }}<br />
|
||||||
|
|
@ -13,25 +14,24 @@
|
||||||
<a href="/schools/{{$school->id}}/edit"> [ Edit School ] </a>
|
<a href="/schools/{{$school->id}}/edit"> [ Edit School ] </a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</x-info-card.row>
|
</x-card.info.row>
|
||||||
|
|
||||||
<x-info-card.row row_name="Directors">
|
<x-card.info.row row_name="Directors">
|
||||||
<ul>
|
<ul>
|
||||||
@foreach($school->directors as $director)
|
@foreach($school->directors as $director)
|
||||||
<li>{{ $director->full_name() }} - <a class='text-indigo-600' href="mailto:{{ $director->email }}">{{ $director->email }}</a></li>
|
<li>{{ $director->full_name() }} - <a class='text-indigo-600' href="mailto:{{ $director->email }}">{{ $director->email }}</a></li>
|
||||||
@endforeach
|
@endforeach
|
||||||
</ul>
|
</ul>
|
||||||
</x-info-card.row>
|
</x-card.info.row>
|
||||||
|
|
||||||
<x-info-card.row row_name="Associated Email Domains">
|
<x-card.info.row row_name="Associated Email Domains">
|
||||||
<ul>
|
<ul>
|
||||||
@foreach($school->emailDomains as $domain)
|
@foreach($school->emailDomains as $domain)
|
||||||
<li>{{ $domain->domain }}</li>
|
<li>{{ $domain->domain }}</li>
|
||||||
@endforeach
|
@endforeach
|
||||||
</ul>
|
</ul>
|
||||||
</x-info-card.row>
|
</x-card.info.row>
|
||||||
|
</x-card.info.body>
|
||||||
|
</x-card.card>
|
||||||
</x-info-card.card>
|
|
||||||
|
|
||||||
</x-layout.app>
|
</x-layout.app>
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,12 @@
|
||||||
@php use App\Models\School;use App\Models\User; @endphp
|
@php use App\Models\School;use App\Models\SchoolEmailDomain;use App\Models\User;use Illuminate\Support\Facades\Auth; @endphp
|
||||||
<x-layout.app>
|
<x-layout.app>
|
||||||
<x-slot:page_title>Test Page</x-slot:page_title>
|
<x-slot:page_title>Test Page</x-slot:page_title>
|
||||||
@php
|
@php
|
||||||
$school = School::first()->emailDomains->pluck('domain');
|
$x = SchoolEmailDomain::with('school')->where('domain','=',Auth::user()->emailDomain())->get();
|
||||||
dd($school);
|
foreach ($x as $y)
|
||||||
|
{
|
||||||
|
echo "<p>" . $y->school->name . "</p>";
|
||||||
|
}
|
||||||
@endphp
|
@endphp
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,20 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use App\Http\Controllers\DashboardController;
|
||||||
use App\Http\Controllers\SchoolController;
|
use App\Http\Controllers\SchoolController;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
|
|
||||||
Route::view('/test','test');
|
Route::view('/test','test');
|
||||||
|
|
||||||
|
Route::get('dashboard', [DashboardController::class, 'dashboard']);
|
||||||
|
Route::get('profile', [DashboardController::class, 'profile']);
|
||||||
|
Route::get('my_school', [DashboardController::class, 'my_school']);
|
||||||
|
|
||||||
Route::view('/','welcome')->middleware('guest');
|
Route::view('/','welcome')->middleware('guest');
|
||||||
Route::view('/profile','profile')->middleware('auth','verified');
|
|
||||||
Route::view('/dashboard', 'dashboard')->middleware('auth', 'verified');
|
|
||||||
|
|
||||||
|
|
||||||
Route::middleware(['auth','verified'])->controller(SchoolController::class)->group(function() {
|
Route::middleware(['auth','verified'])->controller(SchoolController::class)->group(function() {
|
||||||
Route::get('/my_school','my_school');
|
// Route::get('/my_school','my_school');
|
||||||
Route::get('/schools/create', 'create');
|
Route::get('/schools/create', 'create');
|
||||||
Route::post('/schools','store');
|
Route::post('/schools','store');
|
||||||
Route::get('/schools/{school}/edit','edit');
|
Route::get('/schools/{school}/edit','edit');
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue