This commit is contained in:
parent
a161794795
commit
2ad627240f
|
|
@ -1,10 +1,23 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use App\Models\Participant;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
class ParticipantController extends Controller
|
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);
|
Log::info($this->user_id);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function withoutReceivers()
|
||||||
|
{
|
||||||
|
return self::whereNotNull('giving_id')
|
||||||
|
->whereDoesntHave('receiver');
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ class ParticipantFactory extends Factory
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'id' => fake()->unique()->randomNumber(),
|
'id' => fake()->unique()->randomNumber(),
|
||||||
'token' => Str::random(32),
|
'token' => (string) Str::ulid(),
|
||||||
'user_id' => fake()->unique()->randomNumber(),
|
'user_id' => fake()->unique()->randomNumber(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,92 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Models\Participant;
|
use App\Models\Participant;
|
||||||
use Illuminate\Support\Facades\Log;
|
use function Livewire\Volt\{state, mount, rules};
|
||||||
use function Livewire\Volt\{computed, state};
|
|
||||||
|
|
||||||
state(['token'])->url();
|
state(['token'])->url();
|
||||||
|
|
||||||
$participant = computed(function () {
|
state([
|
||||||
return Participant::findByToken($this->token);
|
'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 () {
|
$save = function () {
|
||||||
return $this->participant->getUserData();
|
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>
|
<div>
|
||||||
<pre>{{ $this->participant }}</pre>
|
@if($participant)
|
||||||
@if($this->userData)
|
You are...
|
||||||
<h1><img src ="{{ $this->userData['data']['profile_image_url'] }}"> {{ $this->userData['data']['username'] }}</h1>
|
{{ $participant->id }}
|
||||||
|
@if($userData)
|
||||||
|
<img src ="{{ $userData['data']['profile_image_url'] ?? '' }}">
|
||||||
|
<h1> {{ $userData['data']['username'] ?? 'Unknown' }}</h1>
|
||||||
@endif
|
@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>
|
</div>
|
||||||
@endif
|
@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>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue