Skip to content

Commit

Permalink
fix: fixed modified dates of requests - Ref gestion-de-projet#2261 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ManelleG authored Jul 23, 2024
1 parent 510822c commit decf61c
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/components/Requests/PreviewTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ const RequestsTable = ({ data, loading }: RequestsTableProps) => {
)}
</TableCell>
<TableCell onClick={() => _onClickRow(row)} align="center">
{moment(row.modified_at).format('DD/MM/YYYY [à] HH:mm')}
{moment(row.updated_at).format('DD/MM/YYYY [à] HH:mm')}
</TableCell>
<TableCell align="center">
<Hidden lgDown>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Requests/ProjectsTable/RequestRow/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const RequestRow: React.FC<RequestRowProps> = ({ row, cohortsList, selectedReque
</TableCellWrapper>

<TableCellWrapper className={classes.dateCell}>
{moment(row.modified_at).format('DD/MM/YYYY [à] HH:mm')}
{moment(row.updated_at).format('DD/MM/YYYY [à] HH:mm')}
</TableCellWrapper>
</TableRow>

Expand Down
12 changes: 6 additions & 6 deletions src/components/Requests/ProjectsTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const ProjectTable: React.FC<ProjectTableProps> = ({ searchInput, loading, setSe
const requestsList = useAppSelector((state) => state.request.requestsList)
const cohortsListState = useAppSelector((state) => state.cohort.cohortsList)

const [sortBy, setSortBy] = useState<'name' | 'modified_at'>('name')
const [sortBy, setSortBy] = useState<'name' | 'updated_at'>('name')
const [sortDirection, setSortDirection] = useState<Direction>(Direction.ASC)

const [searchProjectList, setSearchProjectList] = useState(projectsList || [])
Expand Down Expand Up @@ -138,9 +138,9 @@ const ProjectTable: React.FC<ProjectTableProps> = ({ searchInput, loading, setSe
break
}

case 'modified_at': {
case 'updated_at': {
newSearchRequestList = newSearchRequestList.sort((a: RequestType, b: RequestType) => {
if (a.modified_at && b.modified_at && a.modified_at > b.modified_at) {
if (a.updated_at && b.updated_at && a.updated_at > b.updated_at) {
return sortDirection === Direction.ASC ? 1 : -1
} else {
return sortDirection === Direction.ASC ? -1 : 1
Expand Down Expand Up @@ -169,7 +169,7 @@ const ProjectTable: React.FC<ProjectTableProps> = ({ searchInput, loading, setSe
}
}, [sortBy, sortDirection, projectsList, requestsList, cohortList])

const handleRequestSort = (property: 'name' | 'modified_at') => {
const handleRequestSort = (property: 'name' | 'updated_at') => {
const isAsc = sortBy === property && sortDirection === Direction.DESC
setSortDirection(isAsc ? Direction.ASC : Direction.DESC)
setSortBy(property)
Expand Down Expand Up @@ -222,9 +222,9 @@ const ProjectTable: React.FC<ProjectTableProps> = ({ searchInput, loading, setSe
</TableCellWrapper>
<TableCellWrapper className={classes.tableHeadCell} style={{ width: 175 }}>
<TableSortLabel
active={sortBy === Order.MODIFIED}
active={sortBy === Order.UPDATED}
direction={sortDirection || Direction.ASC}
onClick={() => handleRequestSort(Order.MODIFIED)}
onClick={() => handleRequestSort(Order.UPDATED)}
>
Date
</TableSortLabel>
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ export type RequestType = {
deleted_by_cascade?: boolean
created_at?: string
modified_at?: string
updated_at?: string
name: string
description?: string
favorite?: boolean
Expand Down
1 change: 1 addition & 0 deletions src/types/searchCriterias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export enum Order {
IPP = 'identifier',
ID = 'id',
MODIFIED = 'modified_at',
UPDATED = 'updated_at',
NAME = 'name',
MODALITY = 'modality',
DESCRIPTION = 'description',
Expand Down
2 changes: 1 addition & 1 deletion src/views/Welcome/Welcome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const Welcome = () => {
const _lastRequest =
requestState.requestsList?.length > 0
? [...requestState.requestsList]
.sort((a, b) => +moment(b?.modified_at).format('X') - +moment(a.modified_at).format('X'))
.sort((a, b) => +moment(b?.updated_at).format('X') - +moment(a.updated_at).format('X'))
.splice(0, 5)
: []
setLastRequest(_lastRequest)
Expand Down

0 comments on commit decf61c

Please sign in to comment.