// @ts-nocheck import { Button, Intent, MenuItem, Position } from '@blueprintjs/core'; import { useRef, useState, useMemo, useCallback } from 'react'; import { useFormikContext } from 'formik'; import { SelectOptionProps } from '@blueprintjs-formik/select'; import { css } from '@emotion/css'; import { FCheckbox, FFormGroup, FInputGroup, FMultiSelect, FSelect, FTextArea, Group, Icon, Stack, } from '@/components'; import { useDrawerContext } from '@/components/Drawer/DrawerProvider'; import { useDrawerActions } from '@/hooks/state'; import { useInvoiceMailItems, useSendInvoiceFormatArgsOptions } from './_hooks'; import { InvoiceSendMailFormValues } from './_types'; // Create new account renderer. const createNewItemRenderer = ( query: string, active: boolean, handleClick: React.MouseEventHandler, ) => { return ( ); }; // Create new item from the given query string. const createNewItemFromQuery = (text: string): SelectOptionProps => ({ text }); const styleEmailButton = css` &.bp4-button.bp4-small { width: auto; margin: 0; min-height: 26px; line-height: 26px; padding-top: 0; padding-bottom: 0; font-size: 12px; } `; const fieldsWrapStyle = css` > :not(:first-of-type) .bp4-input { border-top-color: transparent; border-top-right-radius: 0; border-top-left-radius: 0; } > :not(:last-of-type) .bp4-input { border-bottom-left-radius: 0; border-bottom-right-radius: 0; } `; export function InvoiceSendMailFields() { const [showCCField, setShowCCField] = useState(false); const [showBccField, setShowBccField] = useState(false); const textareaRef = useRef(null); const { values, setFieldValue } = useFormikContext(); const items = useInvoiceMailItems(); const argsOptions = useSendInvoiceFormatArgsOptions(); const handleClickCcBtn = (event: React.MouseEvent) => { event.preventDefault(); event.stopPropagation(); setShowCCField(true); }; const handleClickBccBtn = (event: React.MouseEvent) => { event.preventDefault(); event.stopPropagation(); setShowBccField(true); }; const handleCreateToItemSelect = (value: SelectOptionProps) => { setFieldValue('to', [...values?.to, value?.text]); }; const handleCreateCcItemSelect = (value: SelectOptionProps) => { setFieldValue('cc', [...values?.cc, value?.text]); }; const handleCreateBccItemSelect = (value: SelectOptionProps) => { setFieldValue('bcc', [...values?.bcc, value?.text]); }; const rightElementsToField = useMemo( () => ( ), [], ); const handleTextareaChange = useCallback( (item: SelectOptionProps) => { const textarea = textareaRef.current; if (!textarea) return; const { selectionStart, selectionEnd, value: text } = textarea; const insertText = `{${item.value}}`; const message = text.substring(0, selectionStart) + insertText + text.substring(selectionEnd); setFieldValue('message', message); // Move the cursor to the end of the inserted text setTimeout(() => { textarea.selectionStart = textarea.selectionEnd = selectionStart + insertText.length; textarea.focus(); }, 0); }, [setFieldValue], ); return ( {showCCField && ( )} {showBccField && ( )} ( )} fill={false} fastField /> ); } function InvoiceSendMailFooter() { const { isSubmitting } = useFormikContext(); const { name } = useDrawerContext(); const { closeDrawer } = useDrawerActions(); const handleClose = () => { closeDrawer(name); }; return ( ); }