From 1122d1daab0f7531d30a3b52e398242bf9daf877 Mon Sep 17 00:00:00 2001 From: sylenien Date: Fri, 7 Oct 2022 17:34:05 +0200 Subject: [PATCH] change(ui): notes slack sharing --- .../Session_/Player/Controls/Time.js | 1 - .../Player/Controls/components/CreateNote.tsx | 95 +++++++++++++------ frontend/app/duck/sessions.js | 2 +- frontend/app/mstore/notesStore.ts | 9 ++ frontend/app/player/Player.ts | 4 +- frontend/app/player/store/store.js | 6 +- frontend/app/services/NotesService.ts | 11 +++ 7 files changed, 91 insertions(+), 37 deletions(-) diff --git a/frontend/app/components/Session_/Player/Controls/Time.js b/frontend/app/components/Session_/Player/Controls/Time.js index ca3c6ce4c..e8221b5b8 100644 --- a/frontend/app/components/Session_/Player/Controls/Time.js +++ b/frontend/app/components/Session_/Player/Controls/Time.js @@ -2,7 +2,6 @@ import React from 'react'; import { Duration } from 'luxon'; import { connectPlayer } from 'Player'; import styles from './time.module.css'; -import { Tooltip } from 'react-tippy'; const Time = ({ time, isCustom, format = 'm:ss', }) => (
diff --git a/frontend/app/components/Session_/Player/Controls/components/CreateNote.tsx b/frontend/app/components/Session_/Player/Controls/components/CreateNote.tsx index 9856a4d69..ba2e11b8b 100644 --- a/frontend/app/components/Session_/Player/Controls/components/CreateNote.tsx +++ b/frontend/app/components/Session_/Player/Controls/components/CreateNote.tsx @@ -8,6 +8,8 @@ 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'; interface Props { isVisible: boolean; @@ -18,6 +20,8 @@ interface Props { sessionId: string; isEdit: string; editNote: WriteNote; + slackChannels: Record[]; + fetchSlack: () => void; } function CreateNote({ @@ -29,12 +33,15 @@ function CreateNote({ 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 inputRef = React.createRef(); const { notesStore } = useStore(); React.useEffect(() => { @@ -50,14 +57,12 @@ function CreateNote({ React.useEffect(() => { if (inputRef.current) { - inputRef.current.focus() + fetchSlack(); + inputRef.current.focus(); } - }, [isVisible]) + }, [isVisible]); const duration = Duration.fromMillis(time).toFormat('mm:ss'); - const stopEvents = (e: any) => { - e.stopPropagation(); - }; const onSubmit = () => { if (text === '') return; @@ -68,29 +73,37 @@ function CreateNote({ 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); - updateNote(r); + 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); }); - }) - .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); @@ -109,7 +122,7 @@ function CreateNote({ }; const closeTooltip = () => { - setCreateNoteTooltip({ isVisible: false, time: 0 }); + setCreateNoteTooltip({ isVisible: false, time: 100 }); }; const tagActive = (noteTag: iTag) => tag === noteTag; @@ -118,17 +131,27 @@ function CreateNote({ setTag(tag); }; + const slackChannelsOptions = slackChannels.map(({ webhookId, name }) => ({ + value: webhookId, + label: name, + })); + + const changeChannel = ({ value, name }: { value: string; name: string }) => { + setChannel(value); + }; + return (
e.stopPropagation()} >
@@ -176,13 +199,23 @@ function CreateNote({ onClick={() => addTag(tag)} > {tagActive(tag) ? : null} -
- {tag} -
+
{tag}
))}
+ {slackChannelsOptions.length > 0 ? ( +
+