-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EmployeeWebClient - create mapQueryParamsBeforeRender hook
- Loading branch information
Showing
22 changed files
with
139 additions
and
39 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
employee-web-client/src/modules/employees/application/employeeCollectionDefaultParams.ts
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,8 @@ | ||
import { DEFAULT_PARAMS } from 'utils/constant'; | ||
|
||
import { IEmployeeCollectionQueryParams } from './types'; | ||
|
||
export const EMPLOYEE_COLLECTION_DEFAULT_PARAMS: IEmployeeCollectionQueryParams = { | ||
order: 'status', | ||
...DEFAULT_PARAMS, | ||
}; |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { useAddEmployeeValidationSchema } from './useAddEmployeeValidationSchema'; | ||
export { useCreateOwnerEmployeeValidationSchema } from './useCreateOwnerEmployeeValidationSchema'; | ||
export { EMPLOYEE_COLLECTION_DEFAULT_PARAMS } from './employeeCollectionDefaultParams'; |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export { useOffersCollectionCheckboxStore } from './offersCollectionCheckboxStore'; | ||
export { OFFER_COLLECTION_DEFAULT_PARAMS } from './offerCollectionDefaultParams'; |
8 changes: 8 additions & 0 deletions
8
employee-web-client/src/modules/offers/application/offerCollectionDefaultParams.ts
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,8 @@ | ||
import { DEFAULT_PARAMS } from 'utils/constant'; | ||
|
||
import { IOfferCollectionQueryParams } from './types'; | ||
|
||
export const OFFER_COLLECTION_DEFAULT_PARAMS: IOfferCollectionQueryParams = { | ||
order: 'status', | ||
...DEFAULT_PARAMS, | ||
}; |
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
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
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export { useQueryParams } from './useQueryParams'; | ||
export { QueryParamsProvider, useQueryParamsConsumer } from './QueryParamsProvider'; | ||
export { filtersAreApplied } from './filtersAreApplied'; | ||
export { withPaginationParamsCorrector } from './withPaginationParamsCorrector'; |
38 changes: 38 additions & 0 deletions
38
employee-web-client/src/shared/Params/mapQueryParamsBeforeRender.tsx
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,38 @@ | ||
import React, { Component, ComponentType } from 'react'; | ||
|
||
import { stringify } from './queryString'; | ||
import { ShareContext, Values } from './QueryParamsProvider'; | ||
import { LocationManager } from './LocationManager'; | ||
|
||
type MapFn<Params> = (routeProps: Values & { params: Params }) => Params; | ||
|
||
export const mapQueryParamsBeforeRender = | ||
<Params extends object>(mapFn: MapFn<Params>) => | ||
(Wrapper: ComponentType) => | ||
// eslint-disable-next-line react/display-name | ||
class extends Component { | ||
static contextType = ShareContext; | ||
|
||
state = { | ||
canRender: false, | ||
}; | ||
|
||
componentDidMount() { | ||
const { history, location } = this.context; | ||
|
||
if (!history || !location) { | ||
throw new Error(`Missing QueryParamsProvider`); | ||
} | ||
|
||
const { params } = LocationManager<Params>(location); | ||
|
||
history.replace(stringify(location.pathname)(mapFn({ history, location, params }))); | ||
this.setState({ canRender: true }); | ||
} | ||
|
||
render() { | ||
if (!this.state.canRender) return null; | ||
|
||
return <Wrapper {...this.props} />; | ||
} | ||
}; |
18 changes: 18 additions & 0 deletions
18
employee-web-client/src/shared/Params/withPaginationParamsCorrector.ts
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,18 @@ | ||
import { mapQueryParamsBeforeRender } from './mapQueryParamsBeforeRender'; | ||
|
||
import { IQueryParams } from 'types'; | ||
|
||
const withPaginationParamsCorrector = (defaults: IQueryParams) => | ||
mapQueryParamsBeforeRender<IQueryParams>(({ params, location }) => { | ||
if (location.search === '') { | ||
return defaults; | ||
} | ||
|
||
if ([isNaN(params.limit), isNaN(params.offset)].some(val => val)) { | ||
return defaults; | ||
} | ||
|
||
return params; | ||
}); | ||
|
||
export { withPaginationParamsCorrector }; |
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,16 @@ | ||
import { ComponentClass, ComponentType } from 'react'; | ||
|
||
interface ComponentEnhancer<TInner, TOutter> { | ||
(component: ComponentType<TInner>): ComponentClass<TOutter>; | ||
} | ||
|
||
function compose<TInner, TOutter>(...funcs: Function[]): ComponentEnhancer<TInner, TOutter> { | ||
return funcs.reduce( | ||
(a, b) => | ||
(...args: Function[]) => | ||
a(b(...args)), | ||
(arg: unknown) => arg, | ||
) as ComponentEnhancer<TInner, TOutter>; | ||
} | ||
|
||
export { compose }; |
Oops, something went wrong.