Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/Http/Controllers/Settings/ApiTokenController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public function store(CreateApiTokenRequest $request)
{
$token = $this->dispatchSync(new CreateApiToken(Auth::user(), $request->name()));

$this->success('settings.api_token.created', ['token' => $token->plainTextToken]);
$this->success('settings.api_token.created');

return redirect()->route('settings.profile');
return redirect()->route('settings.profile')->with('api_token', $token->plainTextToken);
}

public function destroy(DeleteApiTokenRequest $request)
Expand Down
3 changes: 1 addition & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion resources/lang/en/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'deleted' => 'Account was successfully removed.',
'password.updated' => 'Password successfully changed!',
'api_token' => [
'created' => 'API token created! Please copy the following token as it will not be shown again: <span class="bg-white text-gray-800 px-1">:token</span>',
'created' => 'API token created! Please copy the following token as it will not be shown again:',
'deleted' => 'API token successfully removed.',
],
];
24 changes: 24 additions & 0 deletions resources/views/components/api-token.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<div>
<div x-data="{ showApi: false, copyToast: false }" class="flex justify-end items-center">
<input
x-bind:type="!showApi ? 'password' : 'text'" name="apikey" readonly="readonly" value="{{ $token }}"
class="bg-white mr-2 text-gray-800 px-2 py-1 rounded-md"
/>

<x-heroicon-o-clipboard
aria-label="Copy API key"
@@click="navigator.clipboard.writeText('{{ $token }}'); copyToast = true; setTimeout(() => copyToast = false, 4000)"
class="mr-2 text-white h-6 w-6 hover:cursor-pointer"
/>

<x-heroicon-o-eye aria-label="Show Api Key" x-show="!showApi" @@click="showApi = true" class="mr-2 h-6 w-6 text-white hover:cursor-pointer" />

<x-heroicon-o-eye-off aria-label="Hide API Key" x-show="showApi" @@click="showApi = false" class="mr-2 h-6 w-6 text-white hover:cursor-pointer" />

<div x-show="copyToast" x-transition class="fixed bottom-20 left-0 z-10 right-0 flex justify-center items-center">
<span class="text-white z-[99999] bg-gray-800 px-5 py-4 rounded-md text-md">
API Key Copied
</span>
</div>
</div>
</div>
7 changes: 6 additions & 1 deletion resources/views/layouts/_alerts.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@ class="text-xl"

@if (session()->has('success'))
<div class="w-full text-white bg-lio-500 p-4" x-data="{}">
<div class="flex items-center justify-between container mx-auto px-4">
<div class="flex items-center flex-wrap justify-between container mx-auto px-4">
{!! session()->pull('success') !!}

@if (session()->has('api_token'))
<x-api-token :token="session()->pull('api_token')" />
@endif

<button
type="button"
class="text-xl"
Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/SettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
'name' => 'My API Token',
])
->seePageIs('/settings')
->see('API token created! Please copy the following token as it will not be shown again: ');
->see('API token created! Please copy the following token as it will not be shown again:');

expect($user->refresh()->tokens)->toHaveCount(1);
});
Expand Down