Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 2s
141 lines
4.0 KiB
TypeScript
141 lines
4.0 KiB
TypeScript
import type { IOmnichannelRoom } from '@rocket.chat/core-typings';
|
|
import {
|
|
Button,
|
|
Modal,
|
|
Box,
|
|
ModalHeader,
|
|
ModalIcon,
|
|
ModalTitle,
|
|
ModalClose,
|
|
ModalContent,
|
|
ModalFooter,
|
|
ModalFooterControllers,
|
|
} from '@rocket.chat/fuselage';
|
|
import { Field, FieldGroup, FieldLabel, FieldRow, FieldError, TextInput } from '@rocket.chat/fuselage-forms';
|
|
import { useCallback, useEffect } from 'react';
|
|
import { useForm, Controller } from 'react-hook-form';
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
export type TranscriptModalProps = {
|
|
email: string;
|
|
room: IOmnichannelRoom;
|
|
onRequest: (email: string, subject: string) => void;
|
|
onSend?: (email: string, subject: string, token: string) => void;
|
|
onCancel: () => void;
|
|
onDiscard: () => void;
|
|
};
|
|
|
|
const TranscriptModal = ({ email: emailDefault = '', room, onRequest, onSend, onCancel, onDiscard, ...props }: TranscriptModalProps) => {
|
|
const { t } = useTranslation();
|
|
|
|
const {
|
|
control,
|
|
handleSubmit,
|
|
setValue,
|
|
setFocus,
|
|
formState: { errors, isSubmitting },
|
|
} = useForm({
|
|
defaultValues: { email: emailDefault || '', subject: t('Transcript_of_your_livechat_conversation') },
|
|
});
|
|
|
|
useEffect(() => {
|
|
setFocus('subject');
|
|
}, [setFocus]);
|
|
|
|
const { transcriptRequest } = room;
|
|
const roomOpen = room?.open;
|
|
const token = room?.v?.token;
|
|
|
|
const handleDiscard = useCallback(() => onDiscard(), [onDiscard]);
|
|
|
|
const submit = useCallback(
|
|
({ email, subject }: { email: string; subject: string }) => {
|
|
if (roomOpen && !transcriptRequest) {
|
|
onRequest(email, subject);
|
|
}
|
|
if (!roomOpen && onSend && token) {
|
|
onSend(email, subject, token);
|
|
}
|
|
},
|
|
[onRequest, onSend, roomOpen, token, transcriptRequest],
|
|
);
|
|
|
|
useEffect(() => {
|
|
if (transcriptRequest) {
|
|
setValue('email', transcriptRequest.email);
|
|
setValue('subject', transcriptRequest.subject);
|
|
}
|
|
}, [setValue, transcriptRequest]);
|
|
|
|
return (
|
|
<Modal open wrapperFunction={(props) => <Box is='form' onSubmit={handleSubmit(submit)} {...props} />} {...props}>
|
|
<ModalHeader>
|
|
<ModalIcon name='mail-arrow-top-right' />
|
|
<ModalTitle>{t('Transcript')}</ModalTitle>
|
|
<ModalClose onClick={onCancel} />
|
|
</ModalHeader>
|
|
<ModalContent fontScale='p2'>
|
|
{!!transcriptRequest && <p>{t('Livechat_transcript_already_requested_warning')}</p>}
|
|
<FieldGroup>
|
|
<Field>
|
|
<FieldLabel required>{t('Email')}</FieldLabel>
|
|
<FieldRow>
|
|
<Controller
|
|
name='email'
|
|
control={control}
|
|
rules={{ required: t('Required_field', { field: t('Email') }) }}
|
|
render={({ field }) => (
|
|
<TextInput
|
|
{...field}
|
|
disabled={!!emailDefault || !!transcriptRequest}
|
|
error={errors.email?.message}
|
|
flexGrow={1}
|
|
aria-required='true'
|
|
/>
|
|
)}
|
|
/>
|
|
</FieldRow>
|
|
{errors.email && <FieldError>{errors.email?.message}</FieldError>}
|
|
</Field>
|
|
<Field>
|
|
<FieldLabel required>{t('Subject')}</FieldLabel>
|
|
<FieldRow>
|
|
<Controller
|
|
name='subject'
|
|
control={control}
|
|
rules={{ required: t('Required_field', { field: t('Subject') }) }}
|
|
render={({ field }) => (
|
|
<TextInput {...field} disabled={!!transcriptRequest} error={errors.subject?.message} flexGrow={1} aria-required='true' />
|
|
)}
|
|
/>
|
|
</FieldRow>
|
|
{errors.subject && <FieldError>{errors.subject?.message}</FieldError>}
|
|
</Field>
|
|
</FieldGroup>
|
|
</ModalContent>
|
|
<ModalFooter>
|
|
<ModalFooterControllers>
|
|
<Button onClick={onCancel}>{t('Cancel')}</Button>
|
|
{roomOpen && transcriptRequest && (
|
|
<Button danger onClick={handleDiscard}>
|
|
{t('Undo_request')}
|
|
</Button>
|
|
)}
|
|
{roomOpen && !transcriptRequest && (
|
|
<Button disabled={isSubmitting} loading={isSubmitting} primary type='submit'>
|
|
{t('Request')}
|
|
</Button>
|
|
)}
|
|
{!roomOpen && (
|
|
<Button disabled={isSubmitting} loading={isSubmitting} primary type='submit'>
|
|
{t('Send')}
|
|
</Button>
|
|
)}
|
|
</ModalFooterControllers>
|
|
</ModalFooter>
|
|
</Modal>
|
|
);
|
|
};
|
|
|
|
export default TranscriptModal;
|