83 lines
2.9 KiB
PHP
83 lines
2.9 KiB
PHP
<?php
|
|||
|
|
|
||
|
|
use App\Models\Invitation;
|
||
|
|
use App\Models\Organization;
|
||
|
|
use Livewire\Attributes\Title;
|
||
|
|
use Livewire\Component;
|
||
|
|
|
||
|
|
new #[Title('Invitation')] class extends Component
|
||
|
|
{
|
||
|
|
public Invitation $invitation;
|
||
|
|
|
||
|
|
public function mount(Invitation $invitation): void
|
||
|
|
{
|
||
|
|
$this->invitation = $invitation;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Redeem the invitation for the signed-in user, then send them into the
|
||
|
|
* app. Workspace invitations are refused once the workspace is full.
|
||
|
|
*/
|
||
|
|
public function accept(): void
|
||
|
|
{
|
||
|
|
if (! $this->invitation->isValid()) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
$organization = $this->invitation->inviteable;
|
||
|
|
|
||
|
|
if ($organization instanceof Organization && ! $organization->canAddMember()) {
|
||
|
|
$this->addError('invitation', __('This workspace is full, so this invitation can no longer be accepted.'));
|
||
|
|
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
$this->invitation->accept(auth()->user());
|
||
|
|
|
||
|
|
$this->redirect(route('dashboard'), navigate: true);
|
||
|
|
}
|
||
|
|
}; ?>
|
||
|
|
|
||
|
|
<div class="mx-auto flex w-full max-w-xl flex-col gap-6">
|
||
|
|
<flux:heading size="xl">{{ __('Invitation') }}</flux:heading>
|
||
|
|
|
||
|
|
@if ($invitation->isAccepted())
|
||
|
|
<flux:callout variant="success" icon="check-circle" data-test="invitation-accepted">
|
||
|
|
{{ __('This invitation has already been accepted.') }}
|
||
|
|
</flux:callout>
|
||
|
|
@elseif ($invitation->isExpired())
|
||
|
|
<flux:callout variant="warning" icon="clock" data-test="invitation-expired">
|
||
|
|
{{ __('This invitation has expired. Ask the sender to invite you again.') }}
|
||
|
|
</flux:callout>
|
||
|
|
@else
|
||
|
|
<flux:callout icon="envelope" data-test="invitation-summary">
|
||
|
|
@if ($invitation->isForFolder())
|
||
|
|
{{ __(':inviter invited you to collaborate on the folder ":name" as :role.', [
|
||
|
|
'inviter' => $invitation->inviter?->name ?? __('Someone'),
|
||
|
|
'name' => $invitation->inviteable?->name ?? __('a folder'),
|
||
|
|
'role' => $invitation->roleLabel(),
|
||
|
|
]) }}
|
||
|
|
@else
|
||
|
|
{{ __(':inviter invited you to join the ":name" workspace as :role.', [
|
||
|
|
'inviter' => $invitation->inviter?->name ?? __('Someone'),
|
||
|
|
'name' => $invitation->inviteable?->name ?? __('a workspace'),
|
||
|
|
'role' => $invitation->roleLabel(),
|
||
|
|
]) }}
|
||
|
|
@endif
|
||
|
|
</flux:callout>
|
||
|
|
|
||
|
|
@error('invitation')
|
||
|
|
<flux:callout variant="danger" data-test="invitation-error">{{ $message }}</flux:callout>
|
||
|
|
@enderror
|
||
|
|
|
||
|
|
<div class="flex justify-end gap-3">
|
||
|
|
<flux:button variant="ghost" :href="route('dashboard')" wire:navigate>
|
||
|
|
{{ __('Not now') }}
|
||
|
|
</flux:button>
|
||
|
|
<flux:button variant="primary" wire:click="accept" data-test="accept-invitation-button">
|
||
|
|
{{ __('Accept invitation') }}
|
||
|
|
</flux:button>
|
||
|
|
</div>
|
||
|
|
@endif
|
||
|
|
</div>
|