Skip to content

Commit

Permalink
Merge pull request #28 from palladiumkenya/feature/facility-search-fe…
Browse files Browse the repository at this point in the history
…edback

Feat: facility directory search feedback
  • Loading branch information
Ronald-pro authored Aug 27, 2024
2 parents 35313c7 + 289331f commit 4ccc1cb
Show file tree
Hide file tree
Showing 8 changed files with 663 additions and 7 deletions.
27 changes: 27 additions & 0 deletions app/Http/Controllers/DirectoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,31 @@ public function directoryLog(Request $request)

return response()->json(['status' => 'success']);
}

public function directoryRating(Request $request)
{
$mflcode = $request['FacilityCode'];
$rating = $request['Rating'];
$comment = $request['Comment'];

//send this rating value to the facility directory
try {
$apiUrl = env('ART_URL')."facility/directory/rating";

$httpresponse = Http::
withoutVerifying()
->post("$apiUrl", [
'mflcode' => $mflcode,
'rating' => $rating,
'comment' => $comment,
]);

$body = json_decode($httpresponse->getBody(), true);
// return response()->json(['body'=>$body]);
} catch (\Exception $e) {
return response()->json(['status' => 'fail','error'=>$e]);
}

return response()->json(['status' => 'success','mfl_code'=>$mflcode,'rating'=>$rating,'comment'=>$comment]);
}
}
42 changes: 42 additions & 0 deletions app/Http/Controllers/FacilityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Http;
use App\Models\Facility;
use App\Models\County;
use App\Models\Partner;
Expand Down Expand Up @@ -368,4 +369,45 @@ public function edit_facility(Request $request)
return back();
}
}

public function update_contact(Request $request)
{
$validated = $request->validate([
'ccc_phone' => ['required', "regex:/^[0-9][0-9]{9,14}$/", 'max:12'],
'pmtct_phone' => ['required', "regex:/^[0-9][0-9]{9,14}$/", 'max:12'],
]);

//get the facility details
$mflcode = $request->mflcode;
// $partner_name = $request->partner_name;
$ccc_phone = $request->ccc_phone;
$pmtct_phone = $request->pmtct_phone;

//update the facility contact on ART directory
$apiUrl = env('ART_URL')."facility/directory/edit";
$httpresponse = Http::
withoutVerifying()
->post("$apiUrl", [
'mflcode' => $mflcode,
'ccc_phone' => $ccc_phone,
'pmtct_phone' => $pmtct_phone,
]);

$body = json_decode( $httpresponse->getBody(), true);

if (is_array($body) && array_key_exists('status', $body)) {
if ($body['status']) {
Alert::success('Success', 'Facility updated successfully!');
return redirect('/admin/dashboard');
} else {
Alert::error('Failed', 'An error has occurred please try again later.');
return back();
}
}else{
Alert::error('Failed', 'An error has occurred please try again later.');
return back();
}


}
}
25 changes: 24 additions & 1 deletion app/Http/Controllers/NewDashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Illuminate\Support\Facades\Cache;
use Illuminate\Http\Request;

use Illuminate\Support\Facades\Http;

use App\Models\Client;
use App\Models\Appointments;
Expand Down Expand Up @@ -98,6 +98,29 @@ public function dashboard()

// showing all the active clients, all appointments, missed appointments
if (Auth::user()->access_level == 'Facility') {

try {
//check if the facility has maintained a contact in the facility directory
$apiUrl = env('ART_URL')."facility/directory";

$httpresponse = Http::
withoutVerifying()
->get("$apiUrl", [
'code' => Auth::user()->facility_id,
]);

$body = json_decode($httpresponse->getBody(), true);

if($body['message'] !== [])
{
$mflcode = Auth::user()->facility_id;
return view('facilities.facility_contact')->with('mflcode',$mflcode);
}
} catch (\Exception $e) {
// dd($e);
}


$all_partners = Partner::where('status', '=', 'Active')
->remember($this->remember_period)
->pluck('name', 'id');
Expand Down
71 changes: 71 additions & 0 deletions app/View/Components/Rating.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

namespace App\View\Components;

use Illuminate\View\Component;

class Rating extends Component
{
/**
* Create a new component instance.
*
* @return void
*/

/**
* The facility code
*
* @var string
*/

public $mflCode;


/**
* The search rating
*
* @var string
*/

public $searchRating;

/**
* The search counter
*
* @var string
*/

public $searchCounter;

/**
* Create the component instance.
*
* @param string $mflCode
* @param string $searchRating
* @param string $searchCounter
* @return void
*/

public function __construct($mflCode,$searchRating)
{
$this->mflCode = $mflCode;
$this->searchRating = $searchRating;
$this->searchCounter = $searchRating > 0 ? $searchRating : 5;
// dd($mflCode);
}

public function isSelected($option)
{
return $option == $this->searchRating;
}

/**
* Get the view / contents that represent the component.
*
* @return \Illuminate\Contracts\View\View|\Closure|string
*/
public function render()
{
return view('components.rating');
}
}
13 changes: 13 additions & 0 deletions resources/views/components/rating.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<div class="container">
<div class="row">
<div class="col">
<input type="hidden" name="facility_code_rate_{{ $mflCode }}" id="facility_code_rate_{{ $mflCode }}" value="{{ $mflCode }}">

<div class="{{ $searchRating > 0 ? 'rated' : 'rate' }}">
@for($i=1; $i<=$searchCounter; $i++)
<label id="star_{{$i}}" class="star-rating-complete" title="text" data-toggle="modal" data-target="#modal_rating" onclick="document.getElementById('facility_code').value = '{{ $mflCode }}';document.getElementById('star{{$i}}').checked = true;">{{$i}} stars</label>
@endfor
</div>
</div>
</div>
</div>
Loading

0 comments on commit 4ccc1cb

Please sign in to comment.