Skip to content

Commit

Permalink
Fix voucher and sales sorting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
orzechdev committed Apr 19, 2021
1 parent e5df1b2 commit dc6a6e4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/discounts/views/SaleList/SaleList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const SaleList: React.FC<SaleListProps> = ({ params }) => {
() => ({
...paginationState,
filter: getFilterVariables(params),
sort: getSortQueryVariables(params)
sort: getSortQueryVariables(params, channel.slug)
}),
[params]
);
Expand Down
2 changes: 1 addition & 1 deletion src/discounts/views/VoucherList/VoucherList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const VoucherList: React.FC<VoucherListProps> = ({ params }) => {
() => ({
...paginationState,
filter: getFilterVariables(params),
sort: getSortQueryVariables(params)
sort: getSortQueryVariables(params, channel.slug)
}),
[params]
);
Expand Down
7 changes: 4 additions & 3 deletions src/utils/sort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,22 @@ type GetSortQueryField<TUrlField extends string, TSortField extends string> = (
type GetSortQueryVariables<
TSortField extends string,
TParams extends Record<any, any>
> = (params: TParams) => SortingInput<TSortField>;
> = (params: TParams, channelSlug?: string) => SortingInput<TSortField>;
export function createGetSortQueryVariables<
TUrlField extends string,
TSortField extends string,
TParams extends Record<any, any>
>(
getSortQueryField: GetSortQueryField<TUrlField, TSortField>
): GetSortQueryVariables<TSortField, TParams> {
return (params: TParams) => {
return (params: TParams, channelSlug?: string) => {
const field = getSortQueryField(params.sort);

if (!!field) {
return {
direction: getOrderDirection(params.asc),
field
field,
channel: channelSlug
};
}

Expand Down

0 comments on commit dc6a6e4

Please sign in to comment.