93 lines
2.2 KiB
PHP
93 lines
2.2 KiB
PHP
<?php
|
|
|
|
use App\Models\Participant;
|
|
use function Livewire\Volt\{state, mount, rules};
|
|
|
|
state(['token'])->url();
|
|
|
|
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 ?? '';
|
|
}
|
|
}
|
|
});
|
|
|
|
$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;
|
|
};
|
|
|
|
?>
|
|
|
|
<div>
|
|
@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>
|