|
|
@ -8,6 +8,7 @@ import axios from 'axios';
|
|
|
|
import Button from '../Common/Button';
|
|
|
|
import Button from '../Common/Button';
|
|
|
|
import { defineMessages, useIntl } from 'react-intl';
|
|
|
|
import { defineMessages, useIntl } from 'react-intl';
|
|
|
|
import { useUser, Permission } from '../../hooks/useUser';
|
|
|
|
import { useUser, Permission } from '../../hooks/useUser';
|
|
|
|
|
|
|
|
import { useToasts } from 'react-toast-notifications';
|
|
|
|
|
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
const messages = defineMessages({
|
|
|
|
generalsettings: 'General Settings',
|
|
|
|
generalsettings: 'General Settings',
|
|
|
@ -17,15 +18,37 @@ const messages = defineMessages({
|
|
|
|
saving: 'Saving...',
|
|
|
|
saving: 'Saving...',
|
|
|
|
apikey: 'API Key',
|
|
|
|
apikey: 'API Key',
|
|
|
|
applicationurl: 'Application URL',
|
|
|
|
applicationurl: 'Application URL',
|
|
|
|
|
|
|
|
toastApiKeySuccess: 'New API Key generated!',
|
|
|
|
|
|
|
|
toastApiKeyFailure: 'Something went wrong generating a new API Key.',
|
|
|
|
|
|
|
|
toastSettingsSuccess: 'Settings saved.',
|
|
|
|
|
|
|
|
toastSettingsFailure: 'Something went wrong saving settings.',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const SettingsMain: React.FC = () => {
|
|
|
|
const SettingsMain: React.FC = () => {
|
|
|
|
|
|
|
|
const { addToast } = useToasts();
|
|
|
|
const { hasPermission } = useUser();
|
|
|
|
const { hasPermission } = useUser();
|
|
|
|
const intl = useIntl();
|
|
|
|
const intl = useIntl();
|
|
|
|
const { data, error, revalidate } = useSWR<MainSettings>(
|
|
|
|
const { data, error, revalidate } = useSWR<MainSettings>(
|
|
|
|
'/api/v1/settings/main'
|
|
|
|
'/api/v1/settings/main'
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const regenerate = async () => {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
await axios.get('/api/v1/settings/main/regenerate');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
revalidate();
|
|
|
|
|
|
|
|
addToast(intl.formatMessage(messages.toastApiKeySuccess), {
|
|
|
|
|
|
|
|
autoDismiss: true,
|
|
|
|
|
|
|
|
appearance: 'success',
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
|
|
addToast(intl.formatMessage(messages.toastApiKeyFailure), {
|
|
|
|
|
|
|
|
autoDismiss: true,
|
|
|
|
|
|
|
|
appearance: 'error',
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
if (!data && !error) {
|
|
|
|
if (!data && !error) {
|
|
|
|
return <LoadingSpinner />;
|
|
|
|
return <LoadingSpinner />;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -50,8 +73,16 @@ const SettingsMain: React.FC = () => {
|
|
|
|
await axios.post('/api/v1/settings/main', {
|
|
|
|
await axios.post('/api/v1/settings/main', {
|
|
|
|
applicationUrl: values.applicationUrl,
|
|
|
|
applicationUrl: values.applicationUrl,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
addToast(intl.formatMessage(messages.toastSettingsSuccess), {
|
|
|
|
|
|
|
|
autoDismiss: true,
|
|
|
|
|
|
|
|
appearance: 'success',
|
|
|
|
|
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
} catch (e) {
|
|
|
|
// TODO show error
|
|
|
|
addToast(intl.formatMessage(messages.toastSettingsFailure), {
|
|
|
|
|
|
|
|
autoDismiss: true,
|
|
|
|
|
|
|
|
appearance: 'error',
|
|
|
|
|
|
|
|
});
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
revalidate();
|
|
|
|
revalidate();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -77,8 +108,17 @@ const SettingsMain: React.FC = () => {
|
|
|
|
value={data?.apiKey}
|
|
|
|
value={data?.apiKey}
|
|
|
|
readOnly
|
|
|
|
readOnly
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
<CopyButton textToCopy={data?.apiKey ?? ''} />
|
|
|
|
<CopyButton
|
|
|
|
<button className="-ml-px relative inline-flex items-center px-4 py-2 border border-gray-500 text-sm leading-5 font-medium rounded-r-md text-white bg-indigo-500 hover:bg-indigo-400 focus:outline-none focus:ring-blue focus:border-blue-300 active:bg-gray-100 active:text-gray-700 transition ease-in-out duration-150">
|
|
|
|
textToCopy={data?.apiKey ?? ''}
|
|
|
|
|
|
|
|
key={data?.apiKey}
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
<button
|
|
|
|
|
|
|
|
onClick={(e) => {
|
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
regenerate();
|
|
|
|
|
|
|
|
}}
|
|
|
|
|
|
|
|
className="-ml-px relative inline-flex items-center px-4 py-2 border border-gray-500 text-sm leading-5 font-medium rounded-r-md text-white bg-indigo-500 hover:bg-indigo-400 focus:outline-none focus:ring-blue focus:border-blue-300 active:bg-gray-100 active:text-gray-700 transition ease-in-out duration-150"
|
|
|
|
|
|
|
|
>
|
|
|
|
<svg
|
|
|
|
<svg
|
|
|
|
className="w-5 h-5"
|
|
|
|
className="w-5 h-5"
|
|
|
|
fill="currentColor"
|
|
|
|
fill="currentColor"
|
|
|
|