// imports import React, { useState } from 'react'; // locals import Input from '../Input'; import Button from '../Button'; import Overlay from '../Overlay'; import ApiSignal from '../../signals/Api'; import Signal, { useSignal } from '../../signal'; import { current as TeamSignal } from '../../signals/Teams'; // open export const client = new Signal.State(null); export const remove = new Signal.State(null); /** * component client modal * * @param props */ const ComponentClientModal = (props = {}) => { // api const [api] = useSignal(ApiSignal); const [team] = useSignal(TeamSignal); const [sClient, setClient] = useSignal(client); // state const [saving, setSaving] = useState(false); // on save const onSave = async () => { // save client if (saving) return; // set saving setSaving(true); // try/catch try { // save client const result = await api.Client[sClient?.id ? 'update' : 'create']({ ...(sClient || {}), team : team?.id, }); // set client value setClient(result.client); // on change1 if (props.onChange) props.onChange(sClient); } catch (e) { // log console.error(e); } finally { // set saving setSaving(false); } }; // return jsx return ( setClient(null)} subtitle={api.translate('client:dialog.subtitle', 'Create a new API client to access your account')} > setClient({ ...sClient, name : e.target.value })} placeholder={api.translate('client:form.name.placeholder', 'API Client Name')} /> {sClient?.value ? ( ) : (

{api.translate('client:dialog.pending', 'Please save the client to view the API key')}

)}
) }; /** * export component client modal */ export default ComponentClientModal;