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';
|
|
|
|
import ProfileContext from 'app/components/profile/Context';
|
|
|
|
|
|
|
|
const DeleteAccountPage: ComponentType = () => {
|
|
|
|
const context = useContext(ProfileContext);
|
|
|
|
const dispatch = useReduxDispatch();
|
|
|
|
const { current: form } = useRef(new FormModel());
|
|
|
|
const onSubmit = useCallback(
|
|
|
|
() =>
|
|
|
|
context
|
|
|
|
.onSubmit({
|
|
|
|
form,
|
2020-07-27 12:58:37 +05:30
|
|
|
sendData: () => deleteAccount(context.userId, form.serialize()),
|
2020-07-26 22:36:25 +05:30
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
dispatch(
|
|
|
|
updateUser({
|
2020-07-27 12:58:37 +05:30
|
|
|
isDeleted: true,
|
2020-07-26 22:36:25 +05:30
|
|
|
}),
|
|
|
|
);
|
|
|
|
context.goToProfile();
|
|
|
|
}),
|
|
|
|
[context],
|
|
|
|
);
|
|
|
|
|
|
|
|
return <DeleteAccount onSubmit={onSubmit} />;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default DeleteAccountPage;
|