-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a1bd560
commit 7763a19
Showing
2 changed files
with
31 additions
and
24 deletions.
There are no files selected for viewing
26 changes: 17 additions & 9 deletions
26
frontend/src/domain/use_cases/fleetSegment/deleteFleetSegment.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 |
---|---|---|
@@ -1,16 +1,24 @@ | ||
import { deleteFleetSegmentFromAPI } from '../../../api/fleetSegment' | ||
import { deleteFleetSegmentFromAPI } from '@api/fleetSegment' | ||
|
||
import { setError } from '../../shared_slices/Global' | ||
|
||
import type { FleetSegment } from '../../types/fleetSegment' | ||
|
||
/** | ||
* Delete a fleet segment | ||
*/ | ||
export const deleteFleetSegment = (segment: string, year: number) => dispatch => | ||
deleteFleetSegmentFromAPI(segment, year) | ||
.then(updatedFleetSegments => | ||
(Object.assign([], updatedFleetSegments) as FleetSegment[]).sort((a, b) => a.segment.localeCompare(b.segment)) | ||
) | ||
.catch(error => { | ||
dispatch(setError(error)) | ||
}) | ||
export const deleteFleetSegment = | ||
(segment: string, year: number) => | ||
async (dispatch): Promise<undefined | FleetSegment[]> => { | ||
try { | ||
const updatedFleetSegments = await deleteFleetSegmentFromAPI(segment, year) | ||
|
||
return (Object.assign([], updatedFleetSegments) as FleetSegment[]).sort((a, b) => | ||
a.segment.localeCompare(b.segment) | ||
) | ||
} catch (e) { | ||
dispatch(setError(e)) | ||
|
||
return undefined | ||
} | ||
} |
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