2020-12-28 12:11:26 +03:00
|
|
|
import React, { useContext, useEffect } from 'react';
|
2020-12-29 13:51:56 +03:00
|
|
|
import { Typography, Form } from 'antd';
|
2020-12-27 06:44:09 +03:00
|
|
|
|
2020-12-31 05:07:15 +03:00
|
|
|
import TextField, { TEXTFIELD_TYPE_TEXTAREA } from './components/config/form-textfield';
|
2020-12-27 05:04:23 +03:00
|
|
|
|
2021-01-03 11:29:37 +03:00
|
|
|
import EditInstanceTags from './components/config/edit-tags';
|
|
|
|
import EditDirectoryDetails from './components/config/edit-directory';
|
2020-12-31 05:07:15 +03:00
|
|
|
|
|
|
|
import { ServerStatusContext } from '../utils/server-status-context';
|
2021-01-03 11:29:37 +03:00
|
|
|
import { TEXTFIELD_DEFAULTS, postConfigUpdateToAPI } from './components/config/constants';
|
2020-12-27 05:04:23 +03:00
|
|
|
|
|
|
|
const { Title } = Typography;
|
|
|
|
|
|
|
|
export default function PublicFacingDetails() {
|
2020-12-28 12:11:26 +03:00
|
|
|
const [form] = Form.useForm();
|
|
|
|
|
2020-12-27 05:04:23 +03:00
|
|
|
const serverStatusData = useContext(ServerStatusContext);
|
2020-12-29 13:51:56 +03:00
|
|
|
const { serverConfig } = serverStatusData || {};
|
2020-12-27 05:04:23 +03:00
|
|
|
|
2021-01-03 11:29:37 +03:00
|
|
|
const { instanceDetails, yp } = serverConfig;
|
|
|
|
const { instanceDetails: instanceDetailsDefaults, yp: ypDefaults } = TEXTFIELD_DEFAULTS;
|
|
|
|
|
|
|
|
const initialValues = {
|
|
|
|
...instanceDetails,
|
|
|
|
...yp,
|
|
|
|
};
|
|
|
|
|
|
|
|
const defaultFields = {
|
|
|
|
...instanceDetailsDefaults,
|
|
|
|
...ypDefaults,
|
|
|
|
};
|
|
|
|
|
2020-12-28 12:11:26 +03:00
|
|
|
useEffect(() => {
|
2021-01-03 11:29:37 +03:00
|
|
|
form.setFieldsValue(initialValues);
|
2020-12-28 12:11:26 +03:00
|
|
|
}, [instanceDetails]);
|
2020-12-29 13:51:56 +03:00
|
|
|
|
|
|
|
const handleResetValue = (fieldName: string) => {
|
2021-01-03 11:29:37 +03:00
|
|
|
const defaultValue = defaultFields[fieldName] && defaultFields[fieldName].defaultValue || '';
|
|
|
|
|
|
|
|
form.setFieldsValue({ [fieldName]: initialValues[fieldName] || defaultValue });
|
|
|
|
}
|
|
|
|
|
|
|
|
// if instanceUrl is empty, we should also turn OFF the `enabled` field of directory.
|
|
|
|
const handleSubmitInstanceUrl = () => {
|
|
|
|
if (form.getFieldValue('instanceUrl') === '') {
|
|
|
|
if (yp.enabled === true) {
|
|
|
|
const { apiPath } = TEXTFIELD_DEFAULTS.yp.enabled;
|
|
|
|
postConfigUpdateToAPI({
|
|
|
|
apiPath,
|
|
|
|
data: { value: false },
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2020-12-29 13:51:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const extraProps = {
|
|
|
|
handleResetValue,
|
2021-01-03 11:29:37 +03:00
|
|
|
initialValues,
|
|
|
|
configPath: 'instanceDetails',
|
2020-12-29 13:51:56 +03:00
|
|
|
};
|
2020-12-27 05:04:23 +03:00
|
|
|
|
|
|
|
return (
|
2021-01-03 11:29:37 +03:00
|
|
|
<div className="config-public-details-form">
|
2020-12-27 05:04:23 +03:00
|
|
|
<Title level={2}>Edit your public facing instance details</Title>
|
2020-12-28 12:11:26 +03:00
|
|
|
|
2020-12-27 05:04:23 +03:00
|
|
|
<div className="config-public-details-container">
|
2020-12-27 06:44:09 +03:00
|
|
|
<div className="text-fields">
|
2020-12-28 12:11:26 +03:00
|
|
|
<Form
|
|
|
|
form={form}
|
|
|
|
layout="vertical"
|
|
|
|
>
|
2021-01-03 11:29:37 +03:00
|
|
|
<TextField
|
|
|
|
fieldName="instanceUrl"
|
|
|
|
{...extraProps}
|
|
|
|
configPath="yp"
|
|
|
|
onSubmit={handleSubmitInstanceUrl}
|
|
|
|
/>
|
|
|
|
|
2020-12-29 13:51:56 +03:00
|
|
|
<TextField fieldName="title" {...extraProps} />
|
|
|
|
<TextField fieldName="streamTitle" {...extraProps} />
|
2021-01-03 11:29:37 +03:00
|
|
|
<TextField fieldName="name" {...extraProps} />
|
|
|
|
<TextField fieldName="summary" type={TEXTFIELD_TYPE_TEXTAREA} {...extraProps} />
|
|
|
|
<TextField fieldName="logo" {...extraProps} />
|
2020-12-27 06:44:09 +03:00
|
|
|
</Form>
|
2020-12-27 05:04:23 +03:00
|
|
|
</div>
|
2020-12-30 01:47:31 +03:00
|
|
|
<div className="misc-fields">
|
2020-12-31 05:07:15 +03:00
|
|
|
{/* add social handles comp
|
2020-12-27 05:04:23 +03:00
|
|
|
<br/>
|
2020-12-31 05:07:15 +03:00
|
|
|
add tags comp */}
|
|
|
|
<EditInstanceTags />
|
2021-01-03 12:54:04 +03:00
|
|
|
|
2021-01-03 11:29:37 +03:00
|
|
|
<EditDirectoryDetails />
|
2020-12-27 05:04:23 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-01-03 11:29:37 +03:00
|
|
|
</div>
|
2020-12-27 05:04:23 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-12-31 05:07:15 +03:00
|
|
|
|