44 lines
1.2 KiB
TypeScript
44 lines
1.2 KiB
TypeScript
import api from '../api';
|
|
|
|
import type { AxiosError } from 'axios';
|
|
import type { AnyAction } from 'redux';
|
|
import type { RootState } from 'soapbox/store';
|
|
|
|
const ACCOUNT_NOTE_SUBMIT_REQUEST = 'ACCOUNT_NOTE_SUBMIT_REQUEST';
|
|
const ACCOUNT_NOTE_SUBMIT_SUCCESS = 'ACCOUNT_NOTE_SUBMIT_SUCCESS';
|
|
const ACCOUNT_NOTE_SUBMIT_FAIL = 'ACCOUNT_NOTE_SUBMIT_FAIL';
|
|
|
|
const submitAccountNote = (id: string, value: string) =>
|
|
(dispatch: React.Dispatch<AnyAction>, getState: () => RootState) => {
|
|
dispatch(submitAccountNoteRequest());
|
|
|
|
return api(getState)
|
|
.post(`/api/v1/accounts/${id}/note`, {
|
|
comment: value,
|
|
})
|
|
.then(response => {
|
|
dispatch(submitAccountNoteSuccess(response.data));
|
|
})
|
|
.catch(error => dispatch(submitAccountNoteFail(error)));
|
|
};
|
|
|
|
const submitAccountNoteRequest = () => ({
|
|
type: ACCOUNT_NOTE_SUBMIT_REQUEST,
|
|
});
|
|
|
|
const submitAccountNoteSuccess = (relationship: any) => ({
|
|
type: ACCOUNT_NOTE_SUBMIT_SUCCESS,
|
|
relationship,
|
|
});
|
|
|
|
const submitAccountNoteFail = (error: AxiosError) => ({
|
|
type: ACCOUNT_NOTE_SUBMIT_FAIL,
|
|
error,
|
|
});
|
|
|
|
export {
|
|
submitAccountNote,
|
|
ACCOUNT_NOTE_SUBMIT_REQUEST,
|
|
ACCOUNT_NOTE_SUBMIT_SUCCESS,
|
|
ACCOUNT_NOTE_SUBMIT_FAIL,
|
|
};
|