2020-07-26 22:36:25 +05:30
|
|
|
import React, { ComponentType, useCallback, useContext, useRef } from 'react';
|
|
|
|
|
|
|
|
import { useReduxDispatch } from 'app/functions';
|
2020-07-27 12:58:37 +05:30
|
|
|
import { deleteAccount } from 'app/services/api/accounts';
|
2020-07-26 22:36:25 +05:30
|
|
|
import { FormModel } from 'app/components/ui/form';
|
|
|
|
import DeleteAccount from 'app/components/profile/deleteAccount';
|
|
|
|
import { updateUser } from 'app/components/user/actions';
|
2020-10-27 04:16:57 +05:30
|
|
|
import { markAsDeleted } from 'app/components/accounts/actions/pure-actions';
|
2020-07-26 22:36:25 +05:30
|
|
|
import ProfileContext from 'app/components/profile/Context';
|
|
|
|
|
|
|
|
const DeleteAccountPage: ComponentType = () => {
|
|
|
|
const context = useContext(ProfileContext);
|
|
|
|
const dispatch = useReduxDispatch();
|
|
|
|
const { current: form } = useRef(new FormModel());
|
2020-08-04 16:18:16 +05:30
|
|
|
const onSubmit = useCallback(async () => {
|
|
|
|
await context.onSubmit({
|
|
|
|
form,
|
|
|
|
sendData: () => deleteAccount(context.userId, form.serialize()),
|
|
|
|
});
|
|
|
|
dispatch(
|
|
|
|
updateUser({
|
|
|
|
isDeleted: true,
|
|
|
|
}),
|
|
|
|
);
|
2020-10-27 04:16:57 +05:30
|
|
|
dispatch(markAsDeleted(true));
|
2020-08-04 16:18:16 +05:30
|
|
|
context.goToProfile();
|
|
|
|
}, [context]);
|
2020-07-26 22:36:25 +05:30
|
|
|
|
|
|
|
return <DeleteAccount onSubmit={onSubmit} />;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default DeleteAccountPage;
|