mirror of
https://github.com/documenso/documenso.git
synced 2025-11-22 04:31:39 +10:00
chore: refactor
This commit is contained in:
@ -56,18 +56,36 @@ export const TemplatePageViewDocumentsTable = ({
|
|||||||
|
|
||||||
const team = useCurrentTeam();
|
const team = useCurrentTeam();
|
||||||
|
|
||||||
const handleStatusFilterChange = (values: string[]) => {
|
const createFilterHandler = (paramName: string, isSingleValue = false) => {
|
||||||
|
return (values: string[]) => {
|
||||||
startTransition(() => {
|
startTransition(() => {
|
||||||
if (values.length === 0) {
|
if (values.length === 0) {
|
||||||
updateSearchParams({ status: undefined, page: undefined });
|
updateSearchParams({ [paramName]: undefined, page: undefined });
|
||||||
} else {
|
} else {
|
||||||
updateSearchParams({ status: values.join(','), page: undefined });
|
const value = isSingleValue ? values[0] : values.join(',');
|
||||||
|
updateSearchParams({ [paramName]: value, page: undefined });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
|
||||||
const currentStatus = searchParams.get('status');
|
const getFilterValues = (paramName: string, isSingleValue = false): string[] => {
|
||||||
const selectedStatusValues = currentStatus ? currentStatus.split(',').filter(Boolean) : [];
|
const value = searchParams.get(paramName);
|
||||||
|
if (!value) return [];
|
||||||
|
return isSingleValue ? [value] : value.split(',').filter(Boolean);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleStatusFilterChange = createFilterHandler('status');
|
||||||
|
const handleTimePeriodFilterChange = createFilterHandler('period', true);
|
||||||
|
const handleSourceFilterChange = createFilterHandler('source');
|
||||||
|
|
||||||
|
const selectedStatusValues = getFilterValues('status');
|
||||||
|
const selectedTimePeriodValues = getFilterValues('period', true);
|
||||||
|
const selectedSourceValues = getFilterValues('source');
|
||||||
|
|
||||||
|
const isStatusFiltered = selectedStatusValues.length > 0;
|
||||||
|
const isTimePeriodFiltered = selectedTimePeriodValues.length > 0;
|
||||||
|
const isSourceFiltered = selectedSourceValues.length > 0;
|
||||||
|
|
||||||
const handleResetFilters = () => {
|
const handleResetFilters = () => {
|
||||||
startTransition(() => {
|
startTransition(() => {
|
||||||
@ -80,36 +98,6 @@ export const TemplatePageViewDocumentsTable = ({
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const isStatusFiltered = selectedStatusValues.length > 0;
|
|
||||||
|
|
||||||
const handleTimePeriodFilterChange = (values: string[]) => {
|
|
||||||
startTransition(() => {
|
|
||||||
if (values.length === 0) {
|
|
||||||
updateSearchParams({ period: undefined, page: undefined });
|
|
||||||
} else {
|
|
||||||
updateSearchParams({ period: values[0], page: undefined });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const currentPeriod = searchParams.get('period');
|
|
||||||
const selectedTimePeriodValues = currentPeriod ? [currentPeriod] : [];
|
|
||||||
const isTimePeriodFiltered = selectedTimePeriodValues.length > 0;
|
|
||||||
|
|
||||||
const handleSourceFilterChange = (values: string[]) => {
|
|
||||||
startTransition(() => {
|
|
||||||
if (values.length === 0) {
|
|
||||||
updateSearchParams({ source: undefined, page: undefined });
|
|
||||||
} else {
|
|
||||||
updateSearchParams({ source: values.join(','), page: undefined });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const currentSource = searchParams.get('source');
|
|
||||||
const selectedSourceValues = currentSource ? currentSource.split(',').filter(Boolean) : [];
|
|
||||||
const isSourceFiltered = selectedSourceValues.length > 0;
|
|
||||||
|
|
||||||
const sourceParam = searchParams.get('source');
|
const sourceParam = searchParams.get('source');
|
||||||
const statusParam = searchParams.get('status');
|
const statusParam = searchParams.get('status');
|
||||||
const periodParam = searchParams.get('period');
|
const periodParam = searchParams.get('period');
|
||||||
|
|||||||
Reference in New Issue
Block a user