-
Notifications
You must be signed in to change notification settings - Fork 13
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
61df465
commit c69ee43
Showing
3 changed files
with
68 additions
and
89 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { Text, useTheme, PrimaryButton, DefaultButton } from '@fluentui/react'; | ||
import { bold, semibold } from '../../services/Fonts'; | ||
import { useState, useEffect, useContext, CSSProperties } from 'react'; | ||
import { useCookies } from 'react-cookie'; | ||
import { addDays } from 'services/Utils'; | ||
import GlobalContext from 'services/GlobalContext'; | ||
|
||
const LocalizationChangePopup = () => { | ||
var theme = useTheme(); | ||
const [cookies, setCookie] = useCookies(); | ||
const date: Date = addDays(new Date(), 90); | ||
|
||
const localizationPopup: CSSProperties = { | ||
zIndex: 2, | ||
position: 'fixed', | ||
width: '100%', | ||
bottom: 0, | ||
gap: 20, | ||
backgroundColor: theme.palette.white, | ||
borderTop: `1px solid ${theme.palette.neutralQuaternary}`, | ||
padding: '20px 15px' | ||
}; | ||
|
||
const [isDialogOpen, setIsDialogOpen] = useState<boolean>(false); | ||
|
||
const { changeLanguage } = useContext(GlobalContext); | ||
|
||
const setEnglishLocale = () => { | ||
changeLanguage("en"); | ||
setIsDialogOpen(false); | ||
}; | ||
|
||
useEffect(() => { | ||
const acceptLanguage = window.navigator.languages[0] ?? navigator.language; | ||
|
||
if (cookies.isFirstVisit === undefined && acceptLanguage !== "it") { | ||
setIsDialogOpen(true); | ||
} | ||
|
||
setCookie("isFirstVisit", false, { path: "/", expires: date }); | ||
}, []); | ||
|
||
return ( | ||
<> | ||
{ isDialogOpen && | ||
<div style={localizationPopup}> | ||
<div className="d-flex flex-column justify-content-between" style={{ gap: 15 }}> | ||
<div className="d-flex flex-column" style={{ gap: 5 }}> | ||
<Text variant="large" block styles={bold}>You don't speak Italian?</Text> | ||
|
||
<Text variant="medium" styles={semibold} style={{ color: theme.palette.neutralPrimary }}> | ||
Looks like your browser is not set on italian. Would you like to switch to English language? | ||
</Text> | ||
</div> | ||
|
||
<div className="d-flex flex-row" style={{ gap: 15 }}> | ||
<DefaultButton onClick={() => setIsDialogOpen(false)} text="Rimani in italiano" style={{ padding: 18 }} /> | ||
<PrimaryButton onClick={setEnglishLocale} text="Switch to english" style={{ padding: 18 }} /> | ||
</div> | ||
</div> | ||
</div> | ||
} | ||
</> | ||
); | ||
}; | ||
|
||
export default LocalizationChangePopup; |
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