2023-06-22 07:33:26 +00:00
|
|
|
<?php
|
|
|
|
|
2023-12-07 18:06:32 +00:00
|
|
|
namespace App\Livewire\Project;
|
2023-06-22 07:33:26 +00:00
|
|
|
|
|
|
|
use App\Models\Project;
|
|
|
|
use Livewire\Component;
|
|
|
|
|
|
|
|
class Edit extends Component
|
|
|
|
{
|
|
|
|
public Project $project;
|
|
|
|
protected $rules = [
|
|
|
|
'project.name' => 'required|min:3|max:255',
|
|
|
|
'project.description' => 'nullable|string|max:255',
|
|
|
|
];
|
2024-01-23 16:13:23 +00:00
|
|
|
protected $listeners = ['refreshEnvs' => '$refresh', 'saveKey' => 'saveKey'];
|
|
|
|
|
|
|
|
public function saveKey($data)
|
|
|
|
{
|
|
|
|
try {
|
2024-03-15 21:02:37 +00:00
|
|
|
$found = $this->project->environment_variables()->where('key', $data['key'])->first();
|
|
|
|
if ($found) {
|
|
|
|
throw new \Exception('Variable already exists.');
|
|
|
|
}
|
2024-01-23 16:13:23 +00:00
|
|
|
$this->project->environment_variables()->create([
|
|
|
|
'key' => $data['key'],
|
|
|
|
'value' => $data['value'],
|
2024-03-15 21:02:37 +00:00
|
|
|
'is_multiline' => $data['is_multiline'],
|
2024-01-23 16:13:23 +00:00
|
|
|
'type' => 'project',
|
|
|
|
'team_id' => currentTeam()->id,
|
|
|
|
]);
|
|
|
|
$this->project->refresh();
|
|
|
|
} catch (\Throwable $e) {
|
|
|
|
return handleError($e, $this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public function mount()
|
|
|
|
{
|
2024-01-07 15:23:41 +00:00
|
|
|
$projectUuid = request()->route('project_uuid');
|
|
|
|
$teamId = currentTeam()->id;
|
|
|
|
$project = Project::where('team_id', $teamId)->where('uuid', $projectUuid)->first();
|
|
|
|
if (!$project) {
|
|
|
|
return redirect()->route('dashboard');
|
|
|
|
}
|
|
|
|
$this->project = $project;
|
|
|
|
}
|
2023-06-22 13:25:57 +00:00
|
|
|
|
2023-06-22 07:33:26 +00:00
|
|
|
public function submit()
|
|
|
|
{
|
|
|
|
try {
|
2024-03-21 13:30:35 +00:00
|
|
|
$this->validate();
|
2023-06-22 07:33:26 +00:00
|
|
|
$this->project->save();
|
2023-12-07 18:06:32 +00:00
|
|
|
$this->dispatch('saved');
|
2024-03-21 13:30:35 +00:00
|
|
|
$this->dispatch('success', 'Project updated.');
|
2023-09-11 15:36:30 +00:00
|
|
|
} catch (\Throwable $e) {
|
2023-09-15 13:34:25 +00:00
|
|
|
return handleError($e, $this);
|
2023-06-22 07:33:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|