// Copyright 2021 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only import React, { useMemo, useState } from 'react'; import uuid from 'uuid'; import type { LocalizerType } from '../../../types/Util'; import { getMuteOptions } from '../../../util/getMuteOptions'; import { parseIntOrThrow } from '../../../util/parseIntOrThrow'; import { CircleCheckbox, Variant } from '../../CircleCheckbox'; import { Modal } from '../../Modal'; import { Button, ButtonVariant } from '../../Button'; type PropsType = { i18n: LocalizerType; id: string; muteExpiresAt: undefined | number; onClose: () => unknown; setMuteExpiration: ( conversationId: string, muteExpiresAt: undefined | number ) => unknown; }; export function ConversationNotificationsModal({ i18n, id, muteExpiresAt, onClose, setMuteExpiration, }: PropsType): JSX.Element { const muteOptions = useMemo( () => getMuteOptions(muteExpiresAt, i18n) .map(({ disabled, name, value }) => ({ disabled, text: name, value, })) .filter(x => x.value > 0), [i18n, muteExpiresAt] ); const [muteExpirationValue, setMuteExpirationValue] = useState(muteExpiresAt); const onMuteChange = () => { const ms = parseIntOrThrow( muteExpirationValue, 'NotificationSettings: mute ms was not an integer' ); setMuteExpiration(id, ms); onClose(); }; const htmlIds = useMemo(() => { return Array.from({ length: muteOptions.length }, () => uuid()); }, [muteOptions.length]); return ( } > {muteOptions.map((option, i) => ( ))} ); }