2024-01-29 20:09:54 +00:00
|
|
|
// Copyright 2024 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2024-03-13 20:44:13 +00:00
|
|
|
import React, { memo, useCallback } from 'react';
|
2024-01-29 20:09:54 +00:00
|
|
|
import { useSelector } from 'react-redux';
|
|
|
|
|
|
|
|
import { UsernameOnboardingModal } from '../../components/UsernameOnboardingModal';
|
|
|
|
import { EditState } from '../../components/ProfileEditor';
|
|
|
|
import { getIntl } from '../selectors/user';
|
|
|
|
import { useGlobalModalActions } from '../ducks/globalModals';
|
|
|
|
import { useUsernameActions } from '../ducks/username';
|
|
|
|
|
2024-03-13 20:44:13 +00:00
|
|
|
export const SmartUsernameOnboardingModal = memo(
|
|
|
|
function SmartUsernameOnboardingModal(): JSX.Element {
|
|
|
|
const i18n = useSelector(getIntl);
|
|
|
|
const { toggleProfileEditor, toggleUsernameOnboarding } =
|
|
|
|
useGlobalModalActions();
|
|
|
|
const { openUsernameReservationModal } = useUsernameActions();
|
2024-01-29 20:09:54 +00:00
|
|
|
|
2024-03-13 20:44:13 +00:00
|
|
|
const onNext = useCallback(async () => {
|
|
|
|
await window.storage.put('hasCompletedUsernameOnboarding', true);
|
|
|
|
openUsernameReservationModal();
|
|
|
|
toggleProfileEditor(EditState.Username);
|
|
|
|
toggleUsernameOnboarding();
|
|
|
|
}, [
|
|
|
|
toggleProfileEditor,
|
|
|
|
toggleUsernameOnboarding,
|
|
|
|
openUsernameReservationModal,
|
|
|
|
]);
|
2024-01-29 20:09:54 +00:00
|
|
|
|
2024-03-13 20:44:13 +00:00
|
|
|
const onSkip = useCallback(async () => {
|
|
|
|
await window.storage.put('hasCompletedUsernameOnboarding', true);
|
|
|
|
toggleUsernameOnboarding();
|
|
|
|
}, [toggleUsernameOnboarding]);
|
2024-01-29 20:09:54 +00:00
|
|
|
|
2024-03-13 20:44:13 +00:00
|
|
|
return (
|
|
|
|
<UsernameOnboardingModal
|
|
|
|
i18n={i18n}
|
|
|
|
onNext={onNext}
|
|
|
|
onSkip={onSkip}
|
|
|
|
onClose={toggleUsernameOnboarding}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|