1
0
Fork 0
mirror of https://git.sr.ht/~ashkeel/strimertul synced 2024-09-20 02:00:49 +00:00
strimertul/frontend/src/ui/pages/Stulbe.tsx

113 lines
3.3 KiB
TypeScript
Raw Normal View History

2021-05-02 12:29:43 +00:00
import { RouteComponentProps } from '@reach/router';
import React from 'react';
2021-09-17 09:55:15 +00:00
import { useTranslation } from 'react-i18next';
2021-05-02 12:29:43 +00:00
import { useDispatch } from 'react-redux';
import { useModule } from '../../lib/react-utils';
import apiReducer, { modules } from '../../store/api/reducer';
export default function StulbePage(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
params: RouteComponentProps<unknown>,
): React.ReactElement {
2021-09-17 09:55:15 +00:00
const { t } = useTranslation();
2021-05-02 12:29:43 +00:00
const [moduleConfig, setModuleConfig] = useModule(modules.moduleConfig);
const [stulbeConfig, setStulbeConfig] = useModule(modules.stulbeConfig);
const dispatch = useDispatch();
const busy = moduleConfig === null;
const active = moduleConfig?.stulbe ?? false;
return (
<>
2021-09-17 09:55:15 +00:00
<h1 className="title is-4">{t('backend.header')}</h1>
2021-05-02 12:29:43 +00:00
<div className="field">
<label className="checkbox">
<input
type="checkbox"
checked={active}
disabled={busy}
onChange={(ev) =>
dispatch(
apiReducer.actions.moduleConfigChanged({
...moduleConfig,
stulbe: ev.target.checked,
}),
)
}
/>{' '}
2021-09-17 09:55:15 +00:00
{t('backend.enable')}
2021-05-02 12:29:43 +00:00
</label>
</div>
<div className="field">
2021-09-17 09:55:15 +00:00
<label className="label">{t('backend.endpoint')}</label>
2021-05-02 12:29:43 +00:00
<p className="control">
<input
className="input"
type="text"
placeholder="https://stulbe.ovo.ovh"
disabled={busy || !active}
value={stulbeConfig?.endpoint ?? ''}
onChange={(ev) =>
dispatch(
apiReducer.actions.stulbeConfigChanged({
...stulbeConfig,
endpoint: ev.target.value,
}),
)
}
/>
</p>
</div>
2021-05-07 16:36:23 +00:00
<div className="field">
2021-09-17 09:55:15 +00:00
<label className="label">{t('backend.username')}</label>
2021-05-07 16:36:23 +00:00
<p className="control">
<input
className="input"
type="text"
2021-09-17 09:55:15 +00:00
placeholder={t('backend.username-placeholder')}
2021-05-07 16:36:23 +00:00
disabled={busy || !active}
value={stulbeConfig?.username ?? ''}
onChange={(ev) =>
dispatch(
apiReducer.actions.stulbeConfigChanged({
...stulbeConfig,
username: ev.target.value,
}),
)
}
/>
</p>
</div>
<div className="field">
2021-09-17 09:55:15 +00:00
<label className="label">{t('backend.authkey')}</label>
2021-05-07 16:36:23 +00:00
<p className="control">
<input
className="input"
type="password"
2021-09-17 09:55:15 +00:00
placeholder={t('backend.authkey-placeholder')}
2021-05-07 16:36:23 +00:00
disabled={busy || !active}
value={stulbeConfig?.auth_key ?? ''}
onChange={(ev) =>
dispatch(
apiReducer.actions.stulbeConfigChanged({
...stulbeConfig,
auth_key: ev.target.value,
}),
)
}
/>
</p>
</div>
2021-05-02 12:29:43 +00:00
<button
className="button"
onClick={() => {
dispatch(setModuleConfig(moduleConfig));
dispatch(setStulbeConfig(stulbeConfig));
}}
>
Save
</button>
</>
);
}