pleroma/packages/pl-fe/src/actions/account-notes.ts

43 lines
1.3 KiB
TypeScript
Raw Normal View History

import { getClient } from '../api';
2022-05-27 11:08:41 -07:00
import type { AnyAction } from 'redux';
import type { RootState } from 'pl-fe/store';
2022-05-27 11:08:41 -07:00
const ACCOUNT_NOTE_SUBMIT_REQUEST = 'ACCOUNT_NOTE_SUBMIT_REQUEST' as const;
const ACCOUNT_NOTE_SUBMIT_SUCCESS = 'ACCOUNT_NOTE_SUBMIT_SUCCESS' as const;
const ACCOUNT_NOTE_SUBMIT_FAIL = 'ACCOUNT_NOTE_SUBMIT_FAIL' as const;
2022-05-27 11:08:41 -07:00
const submitAccountNote = (accountId: string, value: string) =>
(dispatch: React.Dispatch<AnyAction>, getState: () => RootState) => {
dispatch(submitAccountNoteRequest(accountId));
return getClient(getState).accounts.updateAccountNote(accountId, value)
.then(response => {
dispatch(submitAccountNoteSuccess(response));
}).catch(error => dispatch(submitAccountNoteFail(accountId, error)));
2022-05-27 11:08:41 -07:00
};
const submitAccountNoteRequest = (accountId: string) => ({
type: ACCOUNT_NOTE_SUBMIT_REQUEST,
accountId,
});
2022-05-27 11:08:41 -07:00
const submitAccountNoteSuccess = (relationship: any) => ({
type: ACCOUNT_NOTE_SUBMIT_SUCCESS,
accountId: relationship.id,
relationship,
});
2022-05-27 11:08:41 -07:00
const submitAccountNoteFail = (accountId: string, error: unknown) => ({
type: ACCOUNT_NOTE_SUBMIT_FAIL,
accountId,
error,
});
2022-05-27 11:08:41 -07:00
export {
submitAccountNote,
ACCOUNT_NOTE_SUBMIT_REQUEST,
ACCOUNT_NOTE_SUBMIT_SUCCESS,
ACCOUNT_NOTE_SUBMIT_FAIL,
};