-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
separate functionality between refreshing answer and warning
- Loading branch information
Mailn Nifeli Snieske
committed
Dec 16, 2024
1 parent
cb1a4a7
commit 78d92a1
Showing
11 changed files
with
87 additions
and
105 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
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
15 changes: 0 additions & 15 deletions
15
frontend/beCompliant/src/components/questionPage/LastUpdatedQuestionPage.tsx
This file was deleted.
Oops, something went wrong.
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
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,17 +1,83 @@ | ||
import { Stack, Text } from '@kvib/react'; | ||
import { Stack, Text, IconButton, Tooltip, Icon, Box } from '@kvib/react'; | ||
import { formatDateTime } from '../../utils/formatTime'; | ||
|
||
type Props = { | ||
updated?: Date; | ||
submitAnswer?: (newAnswer: string, unit?: string) => void; | ||
value?: string | undefined; | ||
unitAnswer?: string; | ||
answerExpiry?: number | null; | ||
isComment?: boolean; | ||
isActivityPageView?: boolean; | ||
}; | ||
|
||
export function LastUpdated({ updated }: Props) { | ||
export function LastUpdated({ | ||
updated, | ||
submitAnswer, | ||
value, | ||
unitAnswer, | ||
answerExpiry, | ||
isComment, | ||
isActivityPageView, | ||
}: Props) { | ||
if (!updated) return null; | ||
|
||
const isOlderThan = (updated: Date, weeks?: number | null): boolean => { | ||
const currentDate = new Date(); | ||
const millisecondsInAWeek = 7 * 24 * 60 * 60 * 1000; // One week in milliseconds | ||
const threshold = weeks | ||
? weeks * millisecondsInAWeek | ||
: 30 * 24 * 60 * 60 * 1000; // Use weeks or default to 30 days | ||
return currentDate.getTime() - updated.getTime() > threshold; | ||
}; | ||
|
||
return ( | ||
<Stack color="gray" fontSize="xs" spacing={1} direction="row"> | ||
<Text fontWeight="bold">Sist endret:</Text> | ||
<Text fontWeight="medium">{formatDateTime(updated)}</Text> | ||
<Stack | ||
color="gray" | ||
fontSize={isActivityPageView ? 'xs' : 'md'} | ||
spacing={1} | ||
direction="row" | ||
alignItems="center" | ||
> | ||
<Text | ||
fontWeight={isActivityPageView ? 'bold' : 'semibold'} | ||
color={isActivityPageView ? 'gray' : 'black'} | ||
> | ||
Sist endret: | ||
</Text> | ||
{!isComment && isOlderThan(updated, answerExpiry) && ( | ||
<Tooltip label="Svaret må oppdateres" aria-label="Svaret må oppdateres"> | ||
<Box as="span"> | ||
<Icon icon="warning" color="red" size={28} /> | ||
</Box> | ||
</Tooltip> | ||
)} | ||
<Text | ||
fontWeight={isActivityPageView ? 'medium' : 'semibold'} | ||
color={ | ||
isOlderThan(updated, answerExpiry) && !isComment | ||
? 'red' | ||
: isActivityPageView | ||
? 'gray' | ||
: 'black' | ||
} | ||
> | ||
{formatDateTime(updated)} | ||
</Text> | ||
{!isComment && submitAnswer && ( | ||
<Tooltip label="Forny svaret" aria-label="Forny svaret"> | ||
<IconButton | ||
aria-label="Forny svaret" | ||
icon="autorenew" | ||
color="black" | ||
variant="tertiary" | ||
size="md" | ||
onClick={() => { | ||
submitAnswer(value ?? '', unitAnswer); | ||
}} | ||
/> | ||
</Tooltip> | ||
)} | ||
</Stack> | ||
); | ||
} |
45 changes: 0 additions & 45 deletions
45
frontend/beCompliant/src/components/table/RefreshAnswer.tsx
This file was deleted.
Oops, something went wrong.