import { appTransfer } from '../server';
import { useIntl } from 'umi';
import { Modal, message } from 'antd';
import { UserSelect } from '../index';
import { useState } from 'react';
const AppTransfer = ({ open, setOpen, actionRef }) => {
  const { formatMessage } = useIntl();
  const [userId, setUserId] = useState();
  return (
    <Modal
      title={formatMessage({ id: 'pages.app.transform.creator' })}
      open={open?.isopen}
      destroyOnClose={true}
      keyboard={true}
      mask={false}
      maskClosable={false}
      onCancel={() => {
        setOpen({ ...open, isopen: false });
      }}
      onOk={async () => {
        try {
          await appTransfer({ appId: open?.appId, userId });
          setOpen(false);
          message.success(
            formatMessage({ id: 'pages.app.transform.creator' }) +
              formatMessage({ id: 'base.common.upload.success' }) +
              '!',
          );
          actionRef?.current?.reload();
        } catch {}
      }}
    >
      <UserSelect
        state={1}
        onChange={(val) => {
          setUserId(val);
        }}
      />
    </Modal>
  );
};
export default AppTransfer;
