Skip to content

Commit

Permalink
fix(ui): correct logic for determining which freight are promo eligib…
Browse files Browse the repository at this point in the history
…le (#2024)

Signed-off-by: Remington Breeze <[email protected]>
  • Loading branch information
rbreeze authored May 16, 2024
1 parent 828acc0 commit dd3b715
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions ui/src/features/freightline/freightline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export const Freightline = ({

const promotionEligible = usePromotionEligibleFreight(
availableFreightData?.groups['']?.freight || [],
state.action,
state.stage,
isLoadingAvailableFreight || !isPromoting(state)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@ import { useMemo } from 'react';

import { Freight } from '@ui/gen/v1alpha1/generated_pb';

import { FreightlineAction } from '../types';

export const usePromotionEligibleFreight = (
freight: Freight[],
action?: FreightlineAction,
stage?: string,
disabled?: boolean
) => {
return useMemo(() => {
if (disabled) {
if (disabled || !action) {
return {};
}
const availableFreight = !stage
? freight
: // if promoting subscribers, only include freight that has been verified in the promoting stage
freight.filter((f) => !!f?.status?.verifiedIn[stage]);
const availableFreight =
action === FreightlineAction.Promote || !stage
? freight
: // if promoting subscribers, only include freight that has been verified in the promoting stage
freight.filter((f) => !!f?.status?.verifiedIn[stage]);

const pe: { [key: string]: boolean } = {};
((availableFreight as Freight[]) || []).forEach((f: Freight) => {
Expand Down

0 comments on commit dd3b715

Please sign in to comment.