-
Notifications
You must be signed in to change notification settings - Fork 406
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Show new version warning in change requests (#4153)
- Loading branch information
Showing
4 changed files
with
61 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { FC, useMemo } from 'react' | ||
import { useGetFeatureVersionsQuery } from 'common/services/useFeatureVersion' | ||
import moment from 'moment' | ||
import ErrorMessage from './ErrorMessage' // we need this to make JSX compile | ||
|
||
type NewVersionWarningType = { | ||
date: string | ||
featureId: number | ||
environmentId: string | ||
} | ||
|
||
const NewVersionWarning: FC<NewVersionWarningType> = ({ | ||
date, | ||
environmentId, | ||
featureId, | ||
}) => { | ||
const { data } = useGetFeatureVersionsQuery( | ||
{ environmentId, featureId, is_live: true, page_size: 1 }, | ||
{ refetchOnMountOrArgChange: true, skip: !environmentId || !featureId }, | ||
) | ||
const compareDate = data?.results?.[0]?.live_from | ||
const isNewVersion = useMemo(() => { | ||
if (compareDate && date) { | ||
if (moment(compareDate).valueOf() > moment(date).valueOf()) { | ||
return true | ||
} | ||
} | ||
return false | ||
}, [compareDate, date]) | ||
return isNewVersion ? ( | ||
<div className='mt-4'> | ||
<ErrorMessage | ||
error={`A new change request has been published for this feature since this one was created, please check that the change request is as you'd expect.`} | ||
/> | ||
</div> | ||
) : null | ||
} | ||
|
||
export default NewVersionWarning |
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
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