-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2147 from City-of-Helsinki/hl-870
HL-870 | Wrong number of applications on front page's tabs
- Loading branch information
Showing
6 changed files
with
136 additions
and
96 deletions.
There are no files selected for viewing
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
68 changes: 1 addition & 67 deletions
68
frontend/benefit/handler/src/components/applicationList/useApplicationList.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
77 changes: 77 additions & 0 deletions
77
frontend/benefit/handler/src/components/applicationList/useApplicationListData.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,77 @@ | ||
import useApplicationsQuery from 'benefit/handler/hooks/useApplicationsQuery'; | ||
import { APPLICATION_STATUSES } from 'benefit-shared/constants'; | ||
import { | ||
ApplicationData, | ||
ApplicationListItemData, | ||
} from 'benefit-shared/types/application'; | ||
import { getFullName } from 'shared/utils/application.utils'; | ||
import { convertToUIDateFormat } from 'shared/utils/date.utils'; | ||
|
||
interface ApplicationListProps { | ||
list: ApplicationListItemData[]; | ||
shouldShowSkeleton: boolean; | ||
shouldHideList: boolean; | ||
} | ||
|
||
const useApplicationListData = ( | ||
status: APPLICATION_STATUSES[], | ||
excludeBatched?: boolean | ||
): ApplicationListProps => { | ||
const query = useApplicationsQuery(status, '-submitted_at', excludeBatched); | ||
|
||
const list = query.data?.map( | ||
(application: ApplicationData): ApplicationListItemData => { | ||
const { | ||
id = '', | ||
employee, | ||
company, | ||
submitted_at, | ||
application_number: applicationNum, | ||
calculation, | ||
additional_information_needed_by, | ||
status: applicationStatus, | ||
unread_messages_count, | ||
batch, | ||
application_origin: applicationOrigin, | ||
} = application; | ||
|
||
return { | ||
id, | ||
status: applicationStatus, | ||
companyName: company ? company.name : '-', | ||
companyId: company ? company.business_id : '-', | ||
employeeName: | ||
getFullName(employee?.first_name, employee?.last_name) || '-', | ||
submittedAt: convertToUIDateFormat(submitted_at) || '-', | ||
additionalInformationNeededBy: | ||
convertToUIDateFormat(additional_information_needed_by) || '-', | ||
applicationNum, | ||
// refactor when we have handler data | ||
handlerName: | ||
getFullName( | ||
calculation?.handler_details?.first_name, | ||
calculation?.handler_details?.last_name | ||
) || '-', | ||
unreadMessagesCount: unread_messages_count ?? 0, | ||
batch: batch ?? null, | ||
applicationOrigin, | ||
}; | ||
} | ||
); | ||
|
||
const shouldShowSkeleton = query.isLoading; | ||
|
||
const shouldHideList = | ||
Boolean(query.error) || | ||
(!shouldShowSkeleton && | ||
Array.isArray(query.data) && | ||
query.data.length === 0); | ||
|
||
return { | ||
list: list || [], | ||
shouldShowSkeleton, | ||
shouldHideList, | ||
}; | ||
}; | ||
|
||
export { useApplicationListData }; |
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