import React from 'react'; import { Icon, Button, Checkbox } from 'UI'; import { Duration } from 'luxon'; import { connect } from 'react-redux'; import { WriteNote, tagProps, TAGS, iTag, Note } from 'App/services/NotesService'; import { setCreateNoteTooltip, addNote, updateNote } from 'Duck/sessions'; import stl from './styles.module.css'; import { useStore } from 'App/mstore'; import { toast } from 'react-toastify'; import { injectNotes } from 'Player'; import { fetchList as fetchSlack } from 'Duck/integrations/slack'; import Select from 'Shared/Select'; import { TeamBadge } from 'Shared/SessionListContainer/components/Notes' import { List } from 'immutable'; interface Props { isVisible: boolean; time: number; setCreateNoteTooltip: (state: any) => void; addNote: (note: Note) => void; updateNote: (note: Note) => void; sessionId: string; isEdit: string; editNote: WriteNote; slackChannels: List>; fetchSlack: () => void; } function CreateNote({ isVisible, time, setCreateNoteTooltip, sessionId, addNote, isEdit, editNote, updateNote, slackChannels, fetchSlack, }: Props) { const [text, setText] = React.useState(''); const [channel, setChannel] = React.useState(''); const [isPublic, setPublic] = React.useState(false); const [tag, setTag] = React.useState(TAGS[0]); const [useTimestamp, setUseTs] = React.useState(true); const inputRef = React.createRef(); const { notesStore } = useStore(); React.useEffect(() => { if (isEdit) { setTag(editNote.tag); setText(editNote.message); setPublic(editNote.isPublic); if (editNote.timestamp > 0) { setUseTs(true); } } }, [isEdit]); React.useEffect(() => { if (inputRef.current && isVisible) { fetchSlack(); inputRef.current.focus(); } }, [isVisible]); const duration = Duration.fromMillis(time).toFormat('mm:ss'); const onSubmit = () => { if (text === '') return; const note: WriteNote = { message: text, tag, timestamp: useTimestamp ? (isEdit ? editNote.timestamp : time) : -1, isPublic, }; const onSuccess = (noteId: string) => { if (channel) { notesStore.sendSlackNotification(noteId, channel) } } if (isEdit) { return notesStore .updateNote(editNote.noteId, note) .then((r) => { toast.success('Note updated'); notesStore.fetchSessionNotes(sessionId).then((notes) => { injectNotes(notes); onSuccess(editNote.noteId) updateNote(r); }); }) .catch((e) => { toast.error('Error updating note'); console.error(e); }) .finally(() => { setCreateNoteTooltip({ isVisible: false, time: 0 }); setText(''); setTag(undefined); }); } return notesStore .addNote(sessionId, note) .then((r) => { onSuccess(r.noteId as unknown as string) toast.success('Note added'); notesStore.fetchSessionNotes(sessionId).then((notes) => { injectNotes(notes); addNote(r); }); }) .catch((e) => { toast.error('Error adding note'); console.error(e); }) .finally(() => { setCreateNoteTooltip({ isVisible: false, time: 0 }); setText(''); setTag(undefined); }); }; const closeTooltip = () => { setCreateNoteTooltip({ isVisible: false, time: 100 }); }; const tagActive = (noteTag: iTag) => tag === noteTag; const addTag = (tag: iTag) => { setTag(tag); }; const slackChannelsOptions = slackChannels.map(({ webhookId, name }) => ({ value: webhookId, label: name, })).toJS() as unknown as { value: string, label: string }[] slackChannelsOptions.unshift({ value: null, label: 'Share to slack?' }) const changeChannel = ({ value, name }: { value: Record; name: string }) => { setChannel(value.value); }; return (
0 ? -310 : 255, width: 350, left: 'calc(50% - 175px)', display: isVisible ? 'flex' : 'none', flexDirection: 'column', gap: '1rem', }} onClick={(e) => e.stopPropagation()} >

Add Note

setUseTs(!useTimestamp)}> {`at ${duration}`}