fix: private key change view

This commit is contained in:
Andras Bacsai 2023-05-03 14:24:18 +02:00
parent abf778ce86
commit 48df84fb19
3 changed files with 19 additions and 17 deletions

View File

@ -7,12 +7,18 @@
class Change extends Component
{
public $private_keys;
public string $private_key_uuid;
public PrivateKey $private_key;
public $private_key_uuid;
public $private_key_value;
public $private_key_name;
public $private_key_description;
protected $rules = [
'private_key.name' => 'required|string',
'private_key.description' => 'nullable|string',
'private_key.private_key' => 'required|string'
];
public function mount()
{
$this->private_key = PrivateKey::where('uuid', $this->private_key_uuid)->first();
}
public function delete($private_key_uuid)
{
PrivateKey::where('uuid', $private_key_uuid)->delete();
@ -22,15 +28,11 @@ public function delete($private_key_uuid)
public function changePrivateKey()
{
try {
$this->private_key_value = trim($this->private_key_value);
if (!str_ends_with($this->private_key_value, "\n")) {
$this->private_key_value .= "\n";
$this->private_key->private_key = trim($this->private_key->private_key);
if (!str_ends_with($this->private_key->private_key, "\n")) {
$this->private_key->private_key .= "\n";
}
PrivateKey::where('uuid', $this->private_key_uuid)->update([
'name' => $this->private_key_name,
'description' => $this->private_key_description,
'private_key' => $this->private_key_value,
]);
$this->private_key->save();
session('currentTeam')->privateKeys = PrivateKey::where('team_id', session('currentTeam')->id)->get();
} catch (\Exception $e) {
$this->addError('private_key_value', $e->getMessage());

View File

@ -1,8 +1,8 @@
<div>
<form class="flex flex-col gap-2 w-96" wire:submit.prevent='changePrivateKey'>
<x-inputs.input id="private_key_name" label="Name" required />
<x-inputs.input id="private_key_description" label="Longer Description" />
<x-inputs.input type="textarea" id="private_key_value" label="Private Key" required />
<x-inputs.input id="private_key.name" label="Name" required />
<x-inputs.input id="private_key.description" label="Description" />
<x-inputs.input type="textarea" id="private_key.private_key" label="Private Key" required />
<x-inputs.button type="submit">
Submit
</x-inputs.button>

View File

@ -1,4 +1,4 @@
<x-layout>
<h1>Private Key</h1>
<livewire:private-key.change :private_key_value="$private_key->private_key" :private_key_description="$private_key->description" :private_key_name="$private_key->name" :private_key_uuid="$private_key->uuid" />
<livewire:private-key.change :private_key_uuid="$private_key->uuid" />
</x-layout>