Skip to content

Commit

Permalink
Added types to price calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
Raccoon254 committed May 19, 2024
1 parent f25ab53 commit 0d81a1c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 18 deletions.
21 changes: 11 additions & 10 deletions app/Livewire/PriceCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,24 @@

namespace App\Livewire;

use Illuminate\Support\Facades\Date;
use Illuminate\View\View;
use Livewire\Component;

class PriceCalculator extends Component
{
public $topic;
public $subject;
public $deadline;
public $wordCount;
public $isWords = true;
public $price = 0;
public string $topic;
public string $subject;
public Date $deadline;
public int $wordCount;
public bool $isWords = true;
public int $price = 0;

public function calculatePrice()
public function calculatePrice(): void
{
// Dummy price calculation logic
$ratePerWord = 0.10;
$ratePerPage = 5.00;
// TODO ! Admin should be able to set the rate per word and rate per page
$ratePerWord = 15 / 500;
$ratePerPage = 15.00;
$this->price = $this->isWords
? $this->wordCount * $ratePerWord
: $this->wordCount * $ratePerPage;
Expand Down
2 changes: 1 addition & 1 deletion resources/views/auth/login.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function togglePasswordVisibility() {
<div class="block mt-4">
<label for="remember_me" class="inline-flex items-center">
<input id="remember_me" type="checkbox"
class="rounded border-gray-300 text-indigo-600 shadow-sm focus:ring-indigo-500" name="remember">
class="rounded border-gray-300 text-indigo-600 shadow-sm" name="remember">
<span class="ms-2 text-sm text-gray-600">{{ __('Remember me') }}</span>
</label>
</div>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/components/text-input.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@props(['disabled' => false])

<input {{ $disabled ? 'disabled' : '' }} {!! $attributes->merge(['class' => 'border-gray-300 focus:border-indigo-500 focus:ring-indigo-500 rounded-md shadow-sm']) !!}>
<input {{ $disabled ? 'disabled' : '' }} {!! $attributes->merge(['class' => 'w-full p-2 border border-gray-300 rounded-lg rounded-md shadow-sm']) !!}>
5 changes: 4 additions & 1 deletion resources/views/dashboard.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ class="bg-blue-500 hover:bg-blue-600 text-white font-semibold py-2 px-4 rounded-
</div>

<div class="flex flex-col md:flex-row gap-4 py-2 mt-12">
<livewire:PriceCalculator />
<div class="w-full md:w-1/2">
<livewire:PriceCalculator />
</div>
<div class="records text-black/80">
{{-- TODO ! Previous Actions --}}
</div>
</div>

Expand Down
12 changes: 7 additions & 5 deletions resources/views/livewire/price-calculator.blade.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="bg-white p-6 relative text-black/80 rounded-lg shadow-lg">
<div class="bg-white p-4 relative text-black/80 rounded-lg shadow-sm">
<!-- About icon -->
<a href="#" class="absolute top-0 right-0 bg-blue-500 text-white p-2 rounded-bl-lg rounded-tr-lg hover:bg-blue-600">
<i class="fas h-6 w-6 center fa-info-circle"></i>
<i class="fas h-4 w-4 center fa-info-circle"></i>
</a>
<h3 class="text-lg font-semibold mb-4 text-center">Calculate Order Price</h3>

Expand All @@ -23,10 +23,12 @@
</div>

<div class="mb-4 flex items-center">
<input type="number" wire:model="wordCount" class="flex-grow p-2 border border-gray-300 rounded-lg" placeholder="No of words">
<input type="number" wire:model="wordCount" class="flex-grow p-2 border border-gray-300 w-1/2 rounded-lg" placeholder="No of words">
<div class="ml-2 flex">
<button wire:click="$set('isWords', true)" class="px-4 py-2 border {{ $isWords ? 'bg-green-500 text-white border-green-500' : 'border-gray-300' }} rounded-l-lg">Words</button>
<button wire:click="$set('isWords', false)" class="px-4 py-2 border {{ !$isWords ? 'bg-green-500 text-white border-green-500' : 'border-gray-300' }} rounded-r-lg">Pages</button>
<button wire:click="$set('isWords', true)" class="px-3 py-2 border {{ $isWords ? 'bg-green-500 text-white border-green-500' : 'border-gray-300' }} rounded-l-lg">Words</button>
<button wire:click="$set('isWords', false)" class="px-3 py-2 border {{ !$isWords ? 'bg-green-500 text-white border-green-500' : 'border-gray-300' }} rounded-r-lg">
Pages
</button>
</div>
</div>

Expand Down

0 comments on commit 0d81a1c

Please sign in to comment.