Farmbot-Web-App/frontend/account/actions.ts

38 lines
1.1 KiB
TypeScript
Raw Normal View History

import axios from "axios";
2017-06-29 12:54:02 -06:00
import { Thunk } from "../redux/interfaces";
import { API } from "../api";
import { DeletionRequest } from "./interfaces";
import { Session } from "../session";
2017-08-11 19:54:06 -06:00
import { UnsafeError } from "../interfaces";
import { toastErrors } from "../toast_errors";
2019-05-02 19:37:10 -06:00
import { t } from "../i18next_wrapper";
2017-06-29 12:54:02 -06:00
export function deleteUser(payload: DeletionRequest): Thunk {
return (_, getState) => {
2018-04-02 12:53:37 -06:00
const { auth } = getState();
auth && axios({
method: "delete",
url: API.current.usersPath,
data: payload,
params: { force: true }
})
.then(() => {
alert("We're sorry to see you go. :(");
Session.clear();
2017-06-29 12:54:02 -06:00
})
2018-04-02 12:53:37 -06:00
.catch((err: UnsafeError) => {
toastErrors({ err });
});
2017-06-29 12:54:02 -06:00
};
}
2019-05-02 19:37:10 -06:00
export const resetAccount = (payload: DeletionRequest): Thunk =>
(_, getState) =>
getState().auth && axios({
method: "post",
url: API.current.accountResetPath,
data: payload,
})
.then(() => alert(t("Account has been reset.")))
.catch((err: UnsafeError) => toastErrors({ err }));