// 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 useTeam from '../../hooks/useTeam'; import Signal, { useSignal } from '../../signal'; // open export const key = new Signal.State(null); export const remove = new Signal.State(null); /** * component key modal * * @param props */ const ComponentKeyModal = (props = {}) => { // signals const [api] = useSignal(ApiSignal); const [sKey, setKey] = useSignal(key); // team const team = useTeam(); // state const [saving, setSaving] = useState(false); // on save const onSave = async () => { // save key if (saving) return; // set saving setSaving(true); // try/catch try { // save key const result = await api.Key[sKey?.id ? 'update' : 'create']({ ...sKey, team : team?.id, }); // set key value setKey(result.key); // on change1 if (props.onChange) props.onChange(sKey); } catch (e) { // log console.error(e); } finally { // set saving setSaving(false); } }; // return jsx return ( setKey(null)} subtitle={api.translate('key:dialog.subtitle', 'Create a new API key to access your account')} > setKey({ ...sKey, name : e.target.value })} placeholder={api.translate('key:form.name.placeholder', 'API Key Name')} /> {sKey?.value ? ( ) : (

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

)}
) }; /** * export component key modal */ export default ComponentKeyModal;