Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jxxe committed Nov 28, 2023
1 parent b4c608a commit 5edf114
Show file tree
Hide file tree
Showing 16 changed files with 285 additions and 39 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost

GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=

LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug
Expand Down
36 changes: 36 additions & 0 deletions app/Http/Controllers/AuthController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace App\Http\Controllers;

use App\Models\User;
use Illuminate\Http\Request;
use Laravel\Socialite\Facades\Socialite;
use Laravel\Socialite\Two\InvalidStateException;

class AuthController extends Controller
{
public function redirect()
{
return Socialite::driver('google')->redirect();
}

public function callback()
{
try {
$googleUser = Socialite::driver('google')->user();
} catch(InvalidStateException) {
return redirect()->route('login');
}

$user = User::updateOrCreate([
'email' => $googleUser->email
], [
'name' => $googleUser->name,
'avatar' => $googleUser->avatar
]);

auth()->login($user);

return redirect()->route('dashboard');
}
}
17 changes: 6 additions & 11 deletions app/Livewire/Dashboard/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,32 @@

namespace App\Livewire\Dashboard;

use Illuminate\Http\Request;
use App\Models\Envelope;
use Livewire\Attributes\Locked;
use Livewire\Attributes\Title;
use Livewire\Component;

class Dashboard extends Component
{
#[Locked]
public array $envelopes = [];
public $envelopes = [];

public function mount()
{
$this->envelopes = auth()->user()->envelopes;
}

public function deleteEnvelope(Envelope $envelope)
public function delete(Envelope $envelope)
{
$this->authorize('delete', $envelope);
$envelope->delete();
}

public function archiveEnvelope(Envelope $envelope, bool $newValue)
public function archive(Envelope $envelope)
{
$this->authorize('update', $envelope);
$envelope->update(['archived' => $newValue]);
}

public function renameEnvelope(Envelope $envelope, string $newName)
{
$this->authorize('update', $envelope);
$envelope->update(['name' => $newName]);
$envelope->archived = !$envelope->archived;
$envelope->update();
}

#[Title('Dashboard — Payback')]
Expand Down
13 changes: 0 additions & 13 deletions app/Livewire/Dashboard/Envelope.php

This file was deleted.

24 changes: 24 additions & 0 deletions app/Livewire/Dashboard/EnvelopeCard.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace App\Livewire\Dashboard;

use App\Models\Envelope;
use Livewire\Attributes\Locked;
use Livewire\Component;

class EnvelopeCard extends Component
{
#[Locked]
public Envelope $envelope;

public function rename(string $name)
{
$this->authorize('update', $this->envelope);
$this->envelope->update(['name' => $name]);
}

public function render()
{
return view('livewire.dashboard.envelope-card');
}
}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"guzzlehttp/guzzle": "^7.2",
"laravel/framework": "^10.10",
"laravel/sanctum": "^3.3",
"laravel/socialite": "^5.10",
"laravel/tinker": "^2.8",
"livewire/livewire": "^3.2"
},
Expand Down
148 changes: 147 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,10 @@
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
],

'google' => [
'client_id' => env('GOOGLE_CLIENT_ID'),
'client_secret' => env('GOOGLE_CLIENT_SECRET'),
'redirect' => '/auth/callback',
],

];
1 change: 1 addition & 0 deletions database/factories/ReceiptFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public function definition(): array
{
return [
'name' => fake()->sentence(4),
'store' => fake()->company(),
'amount' => fake()->numberBetween(1_00, 50_00),
'description' => fake()->paragraph(),
'category_id' => Category::inRandomOrder()->first(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public function up(): void
$table->id();

$table->string('name');
$table->string('store');
$table->integer('amount');
$table->text('description')->default('');
$table->string('image')->nullable();
Expand Down
13 changes: 8 additions & 5 deletions database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Models\Receipt;
use App\Models\User;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\App;

class DatabaseSeeder extends Seeder
{
Expand All @@ -16,10 +17,12 @@ class DatabaseSeeder extends Seeder
*/
public function run(): void
{
User::factory(10)->has(
Envelope::factory(5)->has(
Receipt::factory(10)
)
)->create();
if(App::environment() !== 'production') {
User::factory(10)->has(
Envelope::factory(5)->has(
Receipt::factory(10)
)
)->create();
}
}
}
10 changes: 6 additions & 4 deletions resources/views/livewire/dashboard/dashboard.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<div>
@foreach($envelopes as $envelope)
@livewire('dashboard.envelope', $envelope)
@endforeach
<div class="max-w-screen-sm mx-auto p-8">
<div class="grid gap-4 grid-cols-2">
@foreach($envelopes as $envelope)
<livewire:dashboard.envelope-card :$envelope :key="$envelope->id">
@endforeach
</div>
</div>
Loading

0 comments on commit 5edf114

Please sign in to comment.