mirror of
https://github.com/documenso/documenso.git
synced 2026-07-27 18:35:05 +10:00
Merge pull request #142 from raysubham/fix/keep-url-state-in-sync
feat: Keep the URL query params and UI state in sync when status filter changes
This commit is contained in:
@@ -27,7 +27,13 @@ const DocumentsPage: NextPageWithLayout = (props: any) => {
|
|||||||
const [filteredDocuments, setFilteredDocuments] = useState([]);
|
const [filteredDocuments, setFilteredDocuments] = useState([]);
|
||||||
|
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const statusFilters = [
|
|
||||||
|
type statusFilterType = {
|
||||||
|
label: string;
|
||||||
|
value: DocumentStatus | "ALL";
|
||||||
|
};
|
||||||
|
|
||||||
|
const statusFilters: statusFilterType[] = [
|
||||||
{ label: "All", value: "ALL" },
|
{ label: "All", value: "ALL" },
|
||||||
{ label: "Draft", value: "DRAFT" },
|
{ label: "Draft", value: "DRAFT" },
|
||||||
{ label: "Waiting for others", value: "PENDING" },
|
{ label: "Waiting for others", value: "PENDING" },
|
||||||
@@ -83,6 +89,20 @@ const DocumentsPage: NextPageWithLayout = (props: any) => {
|
|||||||
return filteredDocuments;
|
return filteredDocuments;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleStatusFilterChange(status: statusFilterType) {
|
||||||
|
router.replace(
|
||||||
|
{
|
||||||
|
pathname: router.pathname,
|
||||||
|
query: { filter: status.value },
|
||||||
|
},
|
||||||
|
undefined,
|
||||||
|
{
|
||||||
|
shallow: true, // Perform a shallow update, without reloading the page
|
||||||
|
}
|
||||||
|
);
|
||||||
|
setSelectedStatusFilter(status);
|
||||||
|
}
|
||||||
|
|
||||||
function wasXDaysAgoOrLess(documentDate: Date, lastXDays: number): boolean {
|
function wasXDaysAgoOrLess(documentDate: Date, lastXDays: number): boolean {
|
||||||
if (lastXDays < 0) return true;
|
if (lastXDays < 0) return true;
|
||||||
|
|
||||||
@@ -138,7 +158,7 @@ const DocumentsPage: NextPageWithLayout = (props: any) => {
|
|||||||
label="Status"
|
label="Status"
|
||||||
options={statusFilters}
|
options={statusFilters}
|
||||||
value={selectedStatusFilter}
|
value={selectedStatusFilter}
|
||||||
onChange={setSelectedStatusFilter}
|
onChange={handleStatusFilterChange}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="mt-20 max-w-[1100px]" hidden={!loading}>
|
<div className="mt-20 max-w-[1100px]" hidden={!loading}>
|
||||||
|
|||||||
Reference in New Issue
Block a user