2021-01-28 14:08:57 +03:00
|
|
|
import React, { useState, useContext, useEffect } from 'react';
|
2021-02-13 10:55:59 +03:00
|
|
|
import { Typography } from 'antd';
|
|
|
|
|
2021-01-31 12:38:20 +03:00
|
|
|
import TextFieldWithSubmit, {
|
|
|
|
TEXTFIELD_TYPE_TEXTAREA,
|
|
|
|
TEXTFIELD_TYPE_URL,
|
|
|
|
} from './form-textfield-with-submit';
|
2021-01-28 14:08:57 +03:00
|
|
|
|
2021-02-07 06:38:58 +03:00
|
|
|
import { ServerStatusContext } from '../../utils/server-status-context';
|
2021-01-31 12:38:20 +03:00
|
|
|
import {
|
|
|
|
postConfigUpdateToAPI,
|
|
|
|
TEXTFIELD_PROPS_INSTANCE_URL,
|
2021-02-04 10:51:38 +03:00
|
|
|
TEXTFIELD_PROPS_SERVER_NAME,
|
2021-01-31 12:38:20 +03:00
|
|
|
TEXTFIELD_PROPS_SERVER_SUMMARY,
|
|
|
|
API_YP_SWITCH,
|
2021-02-13 10:55:59 +03:00
|
|
|
FIELD_PROPS_YP,
|
|
|
|
FIELD_PROPS_NSFW,
|
2021-02-07 06:38:58 +03:00
|
|
|
} from '../../utils/config-constants';
|
2021-01-28 14:08:57 +03:00
|
|
|
|
2021-02-07 06:38:58 +03:00
|
|
|
import { UpdateArgs } from '../../types/config-section';
|
2021-02-14 12:46:59 +03:00
|
|
|
import ToggleSwitch from './form-toggleswitch';
|
2021-03-22 02:07:12 +03:00
|
|
|
import EditLogo from './edit-logo';
|
2021-02-13 10:55:59 +03:00
|
|
|
|
|
|
|
const { Title } = Typography;
|
2021-01-28 14:08:57 +03:00
|
|
|
|
|
|
|
export default function EditInstanceDetails() {
|
|
|
|
const [formDataValues, setFormDataValues] = useState(null);
|
|
|
|
const serverStatusData = useContext(ServerStatusContext);
|
|
|
|
const { serverConfig } = serverStatusData || {};
|
|
|
|
|
|
|
|
const { instanceDetails, yp } = serverConfig;
|
2021-02-13 10:55:59 +03:00
|
|
|
const { instanceUrl } = yp;
|
2021-01-28 14:08:57 +03:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
setFormDataValues({
|
|
|
|
...instanceDetails,
|
|
|
|
...yp,
|
|
|
|
});
|
|
|
|
}, [instanceDetails, yp]);
|
|
|
|
|
|
|
|
if (!formDataValues) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if instanceUrl is empty, we should also turn OFF the `enabled` field of directory.
|
|
|
|
const handleSubmitInstanceUrl = () => {
|
|
|
|
if (formDataValues.instanceUrl === '') {
|
|
|
|
if (yp.enabled === true) {
|
|
|
|
postConfigUpdateToAPI({
|
|
|
|
apiPath: API_YP_SWITCH,
|
|
|
|
data: { value: false },
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2021-01-31 12:38:20 +03:00
|
|
|
};
|
2021-01-28 14:08:57 +03:00
|
|
|
|
2021-01-29 21:26:55 +03:00
|
|
|
const handleFieldChange = ({ fieldName, value }: UpdateArgs) => {
|
2021-01-28 14:08:57 +03:00
|
|
|
setFormDataValues({
|
|
|
|
...formDataValues,
|
|
|
|
[fieldName]: value,
|
|
|
|
});
|
2021-01-31 12:38:20 +03:00
|
|
|
};
|
2021-01-28 14:08:57 +03:00
|
|
|
|
2021-02-13 10:55:59 +03:00
|
|
|
const hasInstanceUrl = instanceUrl !== '';
|
|
|
|
|
2021-01-31 12:38:20 +03:00
|
|
|
return (
|
2021-02-13 10:55:59 +03:00
|
|
|
<div className="edit-general-settings">
|
|
|
|
<Title level={3} className="section-title">
|
|
|
|
Configure Instance Details
|
|
|
|
</Title>
|
|
|
|
<br />
|
2021-01-31 12:38:20 +03:00
|
|
|
|
2021-02-17 22:17:07 +03:00
|
|
|
<TextFieldWithSubmit
|
|
|
|
fieldName="name"
|
|
|
|
{...TEXTFIELD_PROPS_SERVER_NAME}
|
|
|
|
value={formDataValues.name}
|
|
|
|
initialValue={instanceDetails.name}
|
|
|
|
onChange={handleFieldChange}
|
|
|
|
/>
|
|
|
|
|
2021-02-13 10:55:59 +03:00
|
|
|
<TextFieldWithSubmit
|
|
|
|
fieldName="instanceUrl"
|
|
|
|
{...TEXTFIELD_PROPS_INSTANCE_URL}
|
|
|
|
value={formDataValues.instanceUrl}
|
|
|
|
initialValue={yp.instanceUrl}
|
|
|
|
type={TEXTFIELD_TYPE_URL}
|
|
|
|
onChange={handleFieldChange}
|
|
|
|
onSubmit={handleSubmitInstanceUrl}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<TextFieldWithSubmit
|
|
|
|
fieldName="summary"
|
|
|
|
{...TEXTFIELD_PROPS_SERVER_SUMMARY}
|
|
|
|
type={TEXTFIELD_TYPE_TEXTAREA}
|
|
|
|
value={formDataValues.summary}
|
|
|
|
initialValue={instanceDetails.summary}
|
|
|
|
onChange={handleFieldChange}
|
|
|
|
/>
|
|
|
|
|
2021-03-22 02:07:12 +03:00
|
|
|
{/* Logo section */}
|
|
|
|
<EditLogo />
|
|
|
|
|
|
|
|
<br />
|
2021-02-13 10:55:59 +03:00
|
|
|
<p className="description">
|
2021-02-17 22:17:07 +03:00
|
|
|
Increase your audience by appearing in the{' '}
|
2021-02-13 10:55:59 +03:00
|
|
|
<a href="https://directory.owncast.online" target="_blank" rel="noreferrer">
|
|
|
|
<strong>Owncast Directory</strong>
|
2021-02-26 23:38:55 +03:00
|
|
|
</a>
|
|
|
|
. This is an external service run by the Owncast project.{' '}
|
2021-03-04 11:54:26 +03:00
|
|
|
<a
|
|
|
|
href="https://owncast.online/docs/directory/?source=admin"
|
|
|
|
target="_blank"
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
>
|
2021-02-26 23:38:55 +03:00
|
|
|
Learn more
|
|
|
|
</a>
|
|
|
|
.
|
2021-02-13 10:55:59 +03:00
|
|
|
</p>
|
2021-03-25 00:12:22 +03:00
|
|
|
{!yp.instanceUrl && (
|
|
|
|
<p className="description">
|
|
|
|
You must set your <strong>Server URL</strong> above to enable the directory.
|
|
|
|
</p>
|
|
|
|
)}
|
2021-02-17 22:17:07 +03:00
|
|
|
|
2021-02-13 10:55:59 +03:00
|
|
|
<div className="config-yp-container">
|
|
|
|
<ToggleSwitch
|
|
|
|
fieldName="enabled"
|
|
|
|
useSubmit
|
|
|
|
{...FIELD_PROPS_YP}
|
|
|
|
checked={formDataValues.enabled}
|
|
|
|
disabled={!hasInstanceUrl}
|
2021-01-28 14:08:57 +03:00
|
|
|
/>
|
2021-02-13 10:55:59 +03:00
|
|
|
<ToggleSwitch
|
|
|
|
fieldName="nsfw"
|
|
|
|
useSubmit
|
|
|
|
{...FIELD_PROPS_NSFW}
|
|
|
|
checked={formDataValues.nsfw}
|
|
|
|
disabled={!hasInstanceUrl}
|
2021-01-28 14:08:57 +03:00
|
|
|
/>
|
|
|
|
</div>
|
2021-01-31 12:38:20 +03:00
|
|
|
</div>
|
|
|
|
);
|
2021-01-28 14:08:57 +03:00
|
|
|
}
|