This commit is contained in:
parent
a161794795
commit
2ad627240f
|
|
@ -1,10 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Participant;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class ParticipantController extends Controller
|
||||
{
|
||||
//
|
||||
public function createFromToken(Request $request, string $id)
|
||||
{
|
||||
if ($request->input('password') !== env('ADMIN__PASSWORD')) {
|
||||
return response()->json(['message' => 'Unauthorized: Wrong password'], 401);
|
||||
}
|
||||
|
||||
$participant = Participant::create([
|
||||
'user_id' => $id,
|
||||
'token' => (string) Str::ulid()
|
||||
]);
|
||||
|
||||
return $participant->token;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,4 +63,11 @@ class Participant extends Model
|
|||
Log::info($this->user_id);
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function withoutReceivers()
|
||||
{
|
||||
return self::whereNotNull('giving_id')
|
||||
->whereDoesntHave('receiver');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ class ParticipantFactory extends Factory
|
|||
{
|
||||
return [
|
||||
'id' => fake()->unique()->randomNumber(),
|
||||
'token' => Str::random(32),
|
||||
'token' => (string) Str::ulid(),
|
||||
'user_id' => fake()->unique()->randomNumber(),
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,26 +1,92 @@
|
|||
<?php
|
||||
|
||||
use App\Models\Participant;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use function Livewire\Volt\{computed, state};
|
||||
use function Livewire\Volt\{state, mount, rules};
|
||||
|
||||
state(['token'])->url();
|
||||
|
||||
$participant = computed(function () {
|
||||
return Participant::findByToken($this->token);
|
||||
state([
|
||||
'participant' => null,
|
||||
'userData' => null,
|
||||
'prompt' => '',
|
||||
'isEditing' => false,
|
||||
]);
|
||||
|
||||
rules([
|
||||
'prompt' => 'required|string|min:3',
|
||||
]);
|
||||
|
||||
mount(function () {
|
||||
if ($this->token) {
|
||||
$this->participant = Participant::findByToken($this->token);
|
||||
|
||||
if ($this->participant) {
|
||||
$this->userData = $this->participant->getUserData();
|
||||
$this->prompt = $this->participant->prompt ?? '';
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$userData = computed(function () {
|
||||
return $this->participant->getUserData();
|
||||
});
|
||||
$save = function () {
|
||||
if ($this->participant) {
|
||||
$this->validate();
|
||||
|
||||
$this->participant->prompt = $this->prompt;
|
||||
$this->participant->save();
|
||||
$this->isEditing = false;
|
||||
}
|
||||
};
|
||||
|
||||
$cancel = function () {
|
||||
$this->prompt = $this->participant->prompt ?? '';
|
||||
$this->isEditing = false;
|
||||
};
|
||||
|
||||
?>
|
||||
|
||||
@if($this->participant)
|
||||
<div>
|
||||
<pre>{{ $this->participant }}</pre>
|
||||
@if($this->userData)
|
||||
<h1><img src ="{{ $this->userData['data']['profile_image_url'] }}"> {{ $this->userData['data']['username'] }}</h1>
|
||||
@if($participant)
|
||||
You are...
|
||||
{{ $participant->id }}
|
||||
@if($userData)
|
||||
<img src ="{{ $userData['data']['profile_image_url'] ?? '' }}">
|
||||
<h1> {{ $userData['data']['username'] ?? 'Unknown' }}</h1>
|
||||
@endif
|
||||
<hr>
|
||||
|
||||
@if($isEditing)
|
||||
<form wire:submit="save">
|
||||
<input type="text" id="prompt" wire:model="prompt">
|
||||
|
||||
@error('prompt')
|
||||
<span class="error">{{ $message }}</span>
|
||||
@enderror
|
||||
|
||||
<button type="submit">Save</button>
|
||||
|
||||
<button type="button" wire:click="cancel">Cancel</button>
|
||||
</form>
|
||||
@else
|
||||
<div class="prompt-display">
|
||||
<p>
|
||||
Your prompt is: {{ $prompt ?: 'No prompt set yet.' }}
|
||||
</p>
|
||||
|
||||
<button wire:click="$set('isEditing', true)">
|
||||
{{ $prompt ? 'Edit Prompt' : 'Add Prompt' }}
|
||||
</button>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<hr>
|
||||
|
||||
@if($participant->giving_id)
|
||||
You are giving to <p>{{ $participant->giving_id }}</p>
|
||||
@elseif($participant->desperate)
|
||||
<p>You're in a bind!</p>
|
||||
@else
|
||||
<p>You haven't been assigned anyone.</p>
|
||||
@endif
|
||||
|
||||
@endif
|
||||
</div>
|
||||
@endif
|
||||
|
|
|
|||
Loading…
Reference in New Issue