📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
added password change confirmation modal (#361)
Andrii Romasiundd4d0b0daf04
diff --git a/app/pages/UserSettings/UserSettings.container.tsx b/app/pages/UserSettings/UserSettings.container.tsxindex 11ffa5f69..2519ebcd4 100644--- a/app/pages/UserSettings/UserSettings.container.tsx+++ b/app/pages/UserSettings/UserSettings.container.tsx@@ -8,7 +8,8 @@ import { StateType, AppDispatch } from 'redux/store'import sagaActions from 'redux/sagas/actions'import { IUser } from 'redux/models/IUser'import { ISharedProject } from 'redux/models/ISharedProject'-+import { removeRefreshToken } from 'utils/refreshToken'+import { removeAccessToken } from 'utils/accessToken'import UserSettings from './UserSettings'const mapStateToProps = (state: StateType) => {@@ -126,7 +127,7 @@ const mapDispatchToProps = (dispatch: AppDispatch) => ({updateUserProfileAsync: (data: Partial<IUser>,successMessage: string,- callback = (e: any) => { },+ callback: (isSuccess: boolean) => void = () => { },) => {dispatch(sagaActions.updateUserProfileAsync(data, (res: any) => {@@ -168,6 +169,12 @@ const mapDispatchToProps = (dispatch: AppDispatch) => ({) => {dispatch(sagaActions.updateShowLiveVisitorsInTitle(show, callback))},+ // Reset the user in the regex store and remove tokens+ logoutLocal: () => {+ dispatch(authActions.logout())+ removeRefreshToken()+ removeAccessToken()+ },logoutAll: () => {dispatch(authActions.logout())dispatch(sagaActions.logout(false, true))diff --git a/app/pages/UserSettings/UserSettings.tsx b/app/pages/UserSettings/UserSettings.tsxindex dd79e9a70..9bcce1015 100644--- a/app/pages/UserSettings/UserSettings.tsx+++ b/app/pages/UserSettings/UserSettings.tsx@@ -85,7 +85,7 @@ interface IProps {genericError: (message: string) => void,onGDPRExportFailed: (message: string) => void,updateProfileFailed: (message: string) => void,- updateUserProfileAsync: (data: IUser, successMessage: string, callback?: (e: any) => {}) => void,+ updateUserProfileAsync: (data: IUser, successMessage: string, callback?: (isSuccess: boolean) => void) => void,accountUpdated: (t: string) => void,setAPIKey: (key: string | null) => void,user: IUser,@@ -95,6 +95,7 @@ interface IProps {unlinkSSO: (t: (key: string) => string, callback: (e: any) => void, provider: string) => void,theme: string,updateShowLiveVisitorsInTitle: (show: boolean, callback: (isSuccess: boolean) => void) => void,+ logoutLocal: () => void,logoutAll: () => void,loading: boolean,}@@ -110,7 +111,7 @@ const UserSettings = ({setProjectsShareData, userSharedUpdate, sharedProjectError, updateUserData,genericError, onGDPRExportFailed, updateProfileFailed, updateUserProfileAsync,accountUpdated, setAPIKey, user, dontRemember, isPaidTierUsed, // setThemeType, themeType,- linkSSO, unlinkSSO, theme, updateShowLiveVisitorsInTitle, logoutAll, loading,+ linkSSO, unlinkSSO, theme, updateShowLiveVisitorsInTitle, logoutAll, loading, logoutLocal,}: IProps): JSX.Element => {const navigate = useNavigate()const {@@ -135,6 +136,7 @@ const UserSettings = ({user.timezone || DEFAULT_TIMEZONE,)const [isPaidFeatureOpened, setIsPaidFeatureOpened] = useState<boolean>(false)+ const [isPasswordChangeModalOpened, setIsPasswordChangeModalOpened] = useState<boolean>(false)const [timezoneChanged, setTimezoneChanged] = useState<boolean>(false)const [reportFrequency, setReportFrequency] = useState<string>(user.reportFrequency,@@ -182,8 +184,9 @@ const UserSettings = ({setValidated(valid)}- const onSubmit = (data: any, callback = () => { }) => {+ const onSubmit = (data: any, callback: (isSuccess: boolean) => void = () => { }) => {delete data.repeat+// eslint-disable-next-line no-restricted-syntaxfor (const key in data) {if (data[key] === '') {@@ -191,7 +194,7 @@ const UserSettings = ({}}- updateUserProfileAsync(data, t('profileSettings.updated'))+ updateUserProfileAsync(data, t('profileSettings.updated'), callback)}useEffect(() => {@@ -233,13 +236,21 @@ const UserSettings = ({}))}- const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {- e.preventDefault()- e.stopPropagation()+ const handleSubmit = (e: React.FormEvent<HTMLFormElement> | null, force?: boolean, callback: (isSuccess: boolean) => void = () => { }) => {+ if (e) {+ e.preventDefault()+ e.stopPropagation()+ }setBeenSubmitted(true)if (validated) {- onSubmit(form)+ // User is about to change their password, let's warn him if+ if (form.password && !force) {+ setIsPasswordChangeModalOpened(true)+ return+ }++ onSubmit(form, callback)}}@@ -921,6 +932,26 @@ const UserSettings = ({message={error}isOpened={Boolean(error)}/>+ <Modal+ onClose={() => {+ setIsPasswordChangeModalOpened(false)+ }}+ onSubmit={() => {+ setIsPasswordChangeModalOpened(false)+ handleSubmit(null, true, (isSuccess: boolean) => {+ // password has been changed, let's log out the user as all the sessions are now invalid+ if (isSuccess) {+ logoutLocal()+ }+ })+ }}+ closeText={t('common.cancel')}+ submitText={t('common.continue')}+ type='warning'+ title={t('profileSettings.passwordChangeWarningModal.title')}+ message={t('profileSettings.passwordChangeWarningModal.body')}+ isOpened={isPasswordChangeModalOpened}+ /></div>)}@@ -947,6 +978,8 @@ UserSettings.propTypes = {linkSSO: PropTypes.func.isRequired,unlinkSSO: PropTypes.func.isRequired,theme: PropTypes.string.isRequired,+ logoutLocal: PropTypes.func.isRequired,+ logoutAll: PropTypes.func.isRequired,}export default memo(withAuthentication(UserSettings, auth.authenticated))diff --git a/public/locales/en.json b/public/locales/en.jsonindex 360cb1b6d..ef23fe832 100644--- a/public/locales/en.json+++ b/public/locales/en.json@@ -463,7 +463,11 @@"regenerateSecretKeyMessage": "Are you sure you want to regenerate your secret key?\nAll the existing CAPTCHA widgets will stop working and you will need to update them with the new secret key.","captchaSecretKeyHint": "This is your secret key, it is used to verify the CAPTCHA response on your server. Keep it secret and do not share it with anyone.","showVisitorsInTitle": "Show live visitors in the page title",- "uiSettings": "UI Settings"+ "uiSettings": "UI Settings",+ "passwordChangeWarningModal": {+ "title": "You're about to change your password",+ "body": "You're about to change your password, this will log you out from all devices (including this one) and you will need to log in again with your new password."+ }},"alertsSettings": {"alertCreated": "The alert has been created",