Skip to content

Commit

Permalink
Refactor task updateStatus method
Browse files Browse the repository at this point in the history
  • Loading branch information
Ortiix85 committed Jan 20, 2024
1 parent 7c413f0 commit 6535a75
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 20 deletions.
12 changes: 10 additions & 2 deletions app/Http/Controllers/TaskController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,16 @@ public function getComments($id){

public function updateStatus($id, $status) {
$task = Task::find($id);
$task->status = $status;
$task->save();
$user = AuthUtil::getAuthUser();

if(!$task){
return redirect(route('dashboard'));
}
elseif(UserProject::where("project_id", $task->project->id)->where("user_id", $user->id)->get()->count()){
$task->status = $status;
$task->save();
}
return redirect()->back();
}

public function update(Request $request, $id): string
Expand Down
9 changes: 5 additions & 4 deletions resources/views/app/task.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,17 @@
</div>
<p class="text-sm text-dark-gray">{{$task->description}}</p>
<div class="flex justify-start items-center gap-3">
<x-project-card.date type="deadline" date="{{$project->name}}" />
<x-project-card.date type="deadline" date="{{date('M. d, Y',$deadline)}}" />
</div>
</div>
</div>

<div class="flex justify-start items-center gap-2">
<x-task.button selected="{{$task->status == 0 ? true : false}}" color="cyan-600">To Do</x-task.button>
<x-task.button selected="{{$task->status == 1 ? true : false}}" color="orange-600">In progress</x-task.button>
<x-task.button selected="{{$task->status == 2 ? true : false}}" color="purple-600">In revision</x-task.button>
<x-task.button selected="{{$task->status == 3 ? true : false}}" color="green-600" stylecss="cursor-not-allowed">
<x-task.button :task="$task" selected="{{$task->status == 0 ? true : false}}" color="cyan-600" status=0>To Do</x-task.button>
<x-task.button :task="$task" selected="{{$task->status == 1 ? true : false}}" color="orange-600" status=1>In progress</x-task.button>
<x-task.button :task="$task" selected="{{$task->status == 2 ? true : false}}" color="purple-600" status=2>In revision</x-task.button>
<x-task.button :task="$task" selected="{{$task->status == 3 ? true : false}}" color="green-600" status=3 stylecss="cursor-not-allowed pointer-events-none">
<div class="flex justify-center items-center gap-2">
<x-icons.lock size=16/>
<p>Completed</p>
Expand Down
4 changes: 2 additions & 2 deletions resources/views/components/project-card/date.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
])

@if($type == 'deadline')
<div class="w-32 h-8 flex flex-row justify-center items-center border border-dark-gray rounded-lg gap-2 text-dark-gray">
<div class="px-2 h-8 flex flex-row justify-center items-center border border-dark-gray rounded-lg gap-2 text-dark-gray">
<x-icons.deadline class="stroke-dark-gray" size=16 />
<p class="text-sm">{{$date}}</p>
</div>
@elseif ($type == 'creation')
<div class="w-32 h-8 flex flex-row justify-center items-center border border-dark-gray rounded-lg gap-2 text-dark-gray">
<div class="px-2 h-8 flex flex-row justify-center items-center border border-dark-gray rounded-lg gap-2 text-dark-gray">
<x-icons.creation class="stroke-dark-gray" size=16 />
<p class="text-sm">{{$date}}</p>
</div>
Expand Down
32 changes: 21 additions & 11 deletions resources/views/components/task/button.blade.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
@props(['selected' => false,
'color' => 'black',
'stylecss' => ''])
'color' => 'black',
'stylecss' => '',
'status' => -1,
'task' => null])



@if($selected)
<button class="border-2 border-{{$color}} bg-{{$color}} {{$stylecss}} cursor-default text-white h-8 rounded-lg px-2">
{{$slot}}
</button>
@else
<button class="border-2 border-{{$color}} {{$stylecss}} text-dark-gray h-8 rounded-lg px-2">
{{$slot}}
</button>
@if($task)
@if($selected)
<button class="border-2 border-{{$color}} bg-{{$color}} {{$stylecss}} cursor-default text-white h-8 rounded-lg px-2">
{{$slot}}
</button>
@elseif($task->status != 3)
<form action="{{ route('update.status', ['id' => $task->id, 'status' => $status]) }}" method="post">
@csrf
<button class="border-2 border-{{$color}} {{$stylecss}} text-dark-gray h-8 rounded-lg px-2" type="submit">
{{$slot}}
</button>
</form>
@else
<button class="border-2 border-{{$color}} {{$stylecss}} text-dark-gray h-8 rounded-lg px-2" type="submit">
{{$slot}}
</button>
@endif
@endif
9 changes: 8 additions & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,15 @@
Route::get("/profile/edit", [UserController::class, "edit"])->name("profile.edit")->middleware("auth");
Route::post("/profile", [UserController::class, "update"])->name("profile.update")->middleware("auth");

Route::get("/task/{id}", [TaskController::class, "show"])->name("task")->middleware("auth");
Route::post('/task/{id}/update-status/{status}', [TaskController::class, 'updateStatus'])->name('update.status')->middleware("auth");



Route::redirect("/", "/dashboard");
Route::get("/dashboard", [DashboardController::class, "show"])->name("dashboard")->middleware("auth");
Route::get("/profile", [UserController::class, "show"])->name("profile")->middleware("auth");
Route::get("/project/{id}", [ProjectController::class, "show"])->name("project")->middleware("auth");
Route::get("/task/{id}", [TaskController::class, "show"])->name("task")->middleware("auth");



0 comments on commit 6535a75

Please sign in to comment.