import React, { FC, useState, useEffect } from 'react'; import { Text } from 'ink'; import DappbotAPI from '@eximchain/dappbot-api-client'; import { useResource } from 'react-request-hook'; import { ListDapps } from '@eximchain/dappbot-types/spec/methods/private'; import { isSuccessResponse } from '@eximchain/dappbot-types/spec/responses'; import User from '@eximchain/dappbot-types/spec/user'; import { XOR } from 'ts-xor'; import Dapp from '@eximchain/dappbot-types/spec/dapp'; import { Loader, ErrorBox, errMsgFromResource, ApiMethodLabel, SuccessBox, Select, ChevronText } from '../helpers'; import { StringElt } from '.'; import { Item } from 'ink-select-input'; export interface StageCreateOrUpdateProps { API: DappbotAPI authFile: string setIsUpdate: (isLoading: boolean) => void; setDappName: (DappName: string) => void; addProgressMsg: (msg: StringElt) => void } interface SelectUpdateProps { dapps: Dapp.Item.Api[] setIsUpdate: (isLoading: boolean) => void; setDappName: (DappName: string) => void; label: StringElt[] addProgressMsg: (msg: StringElt) => void } const SelectDappToUpdate: FC = ({ dapps, setIsUpdate, setDappName, label, addProgressMsg }) => { const DappItem = (dapp:Dapp.Item.Api) => ({ label: dapp.DappName, value: dapp.DappName }) function selectDapp(item:Item){ setDappName(item.label); addProgressMsg(Updating the {item.label} dapp.); setIsUpdate(true); } useEffect(function autoSelectLoneDapp() { if (dapps.length === 1) selectDapp(DappItem(dapps[0])) }, [dapps]) return ( You have only created {dapps.length} of the {allowedDapps} dapps in your subscription., Would you like to create a new dapp, or update one of your existing ones? ]} items={[ { label: 'Create', value: 'Create' }, { label: 'Update', value: 'Update' } ]} onSelect={item => { if (item.value === 'Update') { setWantUpdate(true); } else { setIsUpdate(false); addProgressMsg(Creating a new dapp.); } }} /> ) // User has said they want to update, showing them the update prompt return ( Which of your dapps would you like to update?]} /> ) } return ( ) } export default StageCreateOrUpdate;