generated from ainunns/laravel-react-ts-inertia-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add history transaction query * feat: add transaction to navbar * feat: change /transaction to /history * feat: update checkout redirect and enhance transaction index page * feat: add filter by category and date in TransactionController * feat: add history transaction page * feat: add empty transaction state * feat: add search filter to transaction index page * feat: update category filter to support multiple category * feat: add filter transaction by category * feat: add filter by purchase date * fix: cart cant checkout one item * fix: fix timezone --------- Co-authored-by: Ainun Nadhifah Syamsiyah <[email protected]>
- Loading branch information
1 parent
bae42a7
commit 3c2f6f0
Showing
18 changed files
with
566 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Models\Transaction; | ||
use App\Models\Category; | ||
use Illuminate\Support\Facades\Auth; | ||
use Inertia\Inertia; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Carbon; | ||
|
||
class TransactionController extends Controller | ||
{ | ||
public function index(Request $request) | ||
{ | ||
$categoryIds = $request->query('category_id', []); | ||
$startDate = $request->query('start_date'); | ||
$endDate = $request->query('end_date'); | ||
|
||
$category = Category::all(); | ||
|
||
$transaction = Transaction::with(['cart_product.product.category']) | ||
->whereHas('cart_product.product.category', function ($query) use ($categoryIds) { | ||
if (!empty($categoryIds)) { | ||
$query->whereIn('category_id', $categoryIds); | ||
} | ||
}) | ||
->whereHas('cart_product', function ($query) { | ||
$query->where('user_id', Auth::id()); | ||
}); | ||
|
||
if ($startDate && $endDate) { | ||
$transaction = $transaction->whereBetween('created_at', [ | ||
Carbon::parse($startDate)->startOfDay(), | ||
Carbon::parse($endDate)->endOfDay() | ||
]); | ||
} | ||
|
||
$transaction = $transaction->orderBy('created_at', 'desc')->get(); | ||
|
||
return Inertia::render('Transaction/Index', [ | ||
'transaction' => $transaction, | ||
'category' => $category, | ||
'categoryIds' => $categoryIds, | ||
'startDate' => $startDate, | ||
'endDate' => $endDate, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import * as React from "react"; | ||
import { FormProvider, useForm, useWatch } from "react-hook-form"; | ||
import RangeDatePicker from "./Forms/RangeDatepicker"; | ||
|
||
export type PopupFilterProps = { | ||
date: Date[]; | ||
setDate: React.Dispatch<React.SetStateAction<Date[]>>; | ||
onResetFilter?: () => void; | ||
} & React.ComponentPropsWithoutRef<"div">; | ||
|
||
type FormData = { | ||
filter: Date[]; | ||
}; | ||
|
||
export default function DatepickerFilter({ | ||
date, | ||
setDate, | ||
onResetFilter, | ||
}: PopupFilterProps) { | ||
//#region //*=========== Form ===========t | ||
const methods = useForm<FormData>({ | ||
mode: "onTouched", | ||
defaultValues: { | ||
filter: date, | ||
}, | ||
}); | ||
const { control, setValue } = methods; | ||
|
||
const filter = | ||
useWatch({ | ||
control, | ||
name: "filter", | ||
}) ?? []; | ||
//#endregion //*======== Form =========== | ||
|
||
React.useEffect(() => { | ||
setDate(filter); | ||
}, [filter]); | ||
|
||
const resetFilter = () => { | ||
onResetFilter?.(); | ||
setValue("filter", []); | ||
}; | ||
|
||
return ( | ||
<FormProvider {...methods}> | ||
<div className="relative w-80"> | ||
<RangeDatePicker | ||
id="filter" | ||
label={null} | ||
placeholder="Filter by date" | ||
containerClassName="w-full" | ||
isClearable={filter.length > 0} | ||
onClearDate={resetFilter} | ||
/> | ||
</div> | ||
</FormProvider> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.