From 600b8bb1e8e368028a85931d4c555d8a46a9ef84 Mon Sep 17 00:00:00 2001 From: Fedor Katurov Date: Mon, 7 Sep 2020 18:02:59 +0700 Subject: [PATCH] added delete message action --- src/containers/profile/ProfileMessages/index.tsx | 10 ++++++++-- src/redux/auth/actions.ts | 5 +++++ src/redux/auth/constants.ts | 2 ++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/containers/profile/ProfileMessages/index.tsx b/src/containers/profile/ProfileMessages/index.tsx index 5b55746c..810acf71 100644 --- a/src/containers/profile/ProfileMessages/index.tsx +++ b/src/containers/profile/ProfileMessages/index.tsx @@ -15,16 +15,22 @@ const mapStateToProps = state => ({ const mapDispatchToProps = { authGetMessages: AUTH_ACTIONS.authGetMessages, + authDeleteMessage: AUTH_ACTIONS.authDeleteMessage, }; type IProps = ReturnType & typeof mapDispatchToProps & {}; -const ProfileMessagesUnconnected: FC = ({ profile, user: { id }, authGetMessages }) => { +const ProfileMessagesUnconnected: FC = ({ + profile, + user: { id }, + authGetMessages, + authDeleteMessage, +}) => { const [editingMessageId, setEditingMessageId] = useState(0); const onEditMessage = useCallback((id: number) => setEditingMessageId(id), [setEditingMessageId]); const onCancelEdit = useCallback(() => setEditingMessageId(0), [setEditingMessageId]); - const onDeleteMessage = useCallback((id: number) => console.log({ id }), []); + const onDeleteMessage = useCallback((id: number) => authDeleteMessage(id), [authDeleteMessage]); useEffect(() => { if (profile.is_loading || !profile.user || !profile.user.username) return; diff --git a/src/redux/auth/actions.ts b/src/redux/auth/actions.ts index 4c03ae04..942eb3f8 100644 --- a/src/redux/auth/actions.ts +++ b/src/redux/auth/actions.ts @@ -65,6 +65,11 @@ export const authSendMessage = (message: Partial, onSuccess) => ({ onSuccess, }); +export const authDeleteMessage = (id: IMessage['id']) => ({ + type: AUTH_USER_ACTIONS.DELETE_MESSAGE, + id, +}); + export const authSetUpdates = (updates: Partial) => ({ type: AUTH_USER_ACTIONS.SET_UPDATES, updates, diff --git a/src/redux/auth/constants.ts b/src/redux/auth/constants.ts index 82a58918..71fd3f90 100644 --- a/src/redux/auth/constants.ts +++ b/src/redux/auth/constants.ts @@ -14,7 +14,9 @@ export const AUTH_USER_ACTIONS = { LOAD_PROFILE: 'LOAD_PROFILE', SET_PROFILE: 'SET_PROFILE', GET_MESSAGES: 'GET_MESSAGES', + SEND_MESSAGE: 'SEND_MESSAGE', + DELETE_MESSAGE: 'DELETE_MESSAGE', SET_UPDATES: 'SET_UPDATES', SET_LAST_SEEN_MESSAGES: 'SET_LAST_SEEN_MESSAGES',