<commit_before>import { useEffect, useState } from 'react';
import { c } from 'ttag';
import { noop } from '@proton/shared/lib/helpers/function';
import { Contact } from '@proton/shared/lib/interfaces/contacts';
import { getKeyUsedForContact } from '@proton/shared/lib/contacts/keyVerifications';
import { Key } from '@proton/shared/lib/interfaces';
import { APPS } from '@proton/shared/lib/constants';
import { Alert, Copy, FormModal, LinkButton, useAppLink } from '../../../components';
import { useModals, useNotifications, useUser } from '../../../hooks';
import ContactClearDataConfirmModal from './ContactClearDataConfirmModal';
import useContact from '../useContact';

interface Props {
    contactID: string;
    onClose?: () => void;
}

const ContactDecryptionErrorModal = ({ onClose = noop, contactID, ...rest }: Props) => {
    const { createModal } = useModals();
    const { createNotification } = useNotifications();
    const [user] = useUser();
    const [contact] = useContact(contactID) as [Contact | undefined, boolean, Error];
    const [errorKey, setErrorKey] = useState<Key>();
    const appLink = useAppLink();

    useEffect(() => {
        const findKey = async () => {
            const key = await getKeyUsedForContact(contact as Contact, user.Keys, true);
            setErrorKey(key);
        };

        if (user && contact) {
            void findKey();
        }
    }, [user, contact]);

    const handleSubmit = () => {
        appLink('/mail/encryption-keys', APPS.PROTONACCOUNT);
    };

    const handleClear = () => {
        createModal(<ContactClearDataConfirmModal errorKey={errorKey as Key} />);
        onClose();
    };

    return (
        <FormModal<commit_msg>Fix settings link in contact decryption modal<commit_after>import { useEffect, useState } from 'react';
import { c } from 'ttag';
import { noop } from '@proton/shared/lib/helpers/function';
import { Contact } from '@proton/shared/lib/interfaces/contacts';
import { getKeyUsedForContact } from '@proton/shared/lib/contacts/keyVerifications';
import { Key } from '@proton/shared/lib/interfaces';
import { APPS } from '@proton/shared/lib/constants';
import { Alert, Copy, FormModal, LinkButton, useSettingsLink } from '../../../components';
import { useModals, useNotifications, useUser } from '../../../hooks';
import ContactClearDataConfirmModal from './ContactClearDataConfirmModal';
import useContact from '../useContact';

interface Props {
    contactID: string;
    onClose?: () => void;
}

const ContactDecryptionErrorModal = ({ onClose = noop, contactID, ...rest }: Props) => {
    const { createModal } = useModals();
    const { createNotification } = useNotifications();
    const [user] = useUser();
    const [contact] = useContact(contactID) as [Contact | undefined, boolean, Error];
    const [errorKey, setErrorKey] = useState<Key>();
    const goToSettings = useSettingsLink();

    useEffect(() => {
        const findKey = async () => {
            const key = await getKeyUsedForContact(contact as Contact, user.Keys, true);
            setErrorKey(key);
        };

        if (user && contact) {
            void findKey();
        }
    }, [user, contact]);

    const handleSubmit = () => {
        goToSettings('/encryption-keys', APPS.PROTONMAIL);
    };

    const handleClear = () => {
        createModal(<ContactClearDataConfirmModal errorKey={errorKey as Key} />);
        onClose();
    };

    return (
        <FormModal
{'fraction_non_alphanumeric': 0.14710982658959537, 'fraction_numerical': 0.0, 'mean_word_length': 3.294044665012407, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3838305', 'n_tokens_mistral': 983, 'n_tokens_neox': 983, 'n_words': 247}