2020-12-28 10:11:26 +01:00
|
|
|
import React, { useContext, useEffect } from 'react';
|
2020-12-29 11:51:56 +01:00
|
|
|
import { Typography, Form } from 'antd';
|
2021-01-09 22:12:14 +01:00
|
|
|
import Link from 'next/link';
|
2020-12-27 04:44:09 +01:00
|
|
|
|
2021-01-03 13:03:18 +01:00
|
|
|
import TextField, { TEXTFIELD_TYPE_TEXTAREA, TEXTFIELD_TYPE_URL } from './components/config/form-textfield';
|
2020-12-27 03:04:23 +01:00
|
|
|
|
2020-12-31 03:07:15 +01:00
|
|
|
import { ServerStatusContext } from '../utils/server-status-context';
|
2021-01-03 09:29:37 +01:00
|
|
|
import { TEXTFIELD_DEFAULTS, postConfigUpdateToAPI } from './components/config/constants';
|
2020-12-27 03:04:23 +01:00
|
|
|
|
2021-01-27 10:46:08 +01:00
|
|
|
import configStyles from '../styles/config-pages.module.scss';
|
|
|
|
|
2020-12-27 03:04:23 +01:00
|
|
|
const { Title } = Typography;
|
|
|
|
|
|
|
|
export default function PublicFacingDetails() {
|
2020-12-28 10:11:26 +01:00
|
|
|
const [form] = Form.useForm();
|
|
|
|
|
2020-12-27 03:04:23 +01:00
|
|
|
const serverStatusData = useContext(ServerStatusContext);
|
2020-12-29 11:51:56 +01:00
|
|
|
const { serverConfig } = serverStatusData || {};
|
2020-12-27 03:04:23 +01:00
|
|
|
|
2021-01-03 09:29:37 +01:00
|
|
|
const { instanceDetails, yp } = serverConfig;
|
|
|
|
|
|
|
|
const initialValues = {
|
|
|
|
...instanceDetails,
|
|
|
|
...yp,
|
|
|
|
};
|
|
|
|
|
2020-12-28 10:11:26 +01:00
|
|
|
useEffect(() => {
|
2021-01-03 09:29:37 +01:00
|
|
|
form.setFieldsValue(initialValues);
|
2020-12-28 10:11:26 +01:00
|
|
|
}, [instanceDetails]);
|
2020-12-29 11:51:56 +01:00
|
|
|
|
2021-01-03 09:29:37 +01:00
|
|
|
|
|
|
|
// 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 11:51:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const extraProps = {
|
2021-01-03 09:29:37 +01:00
|
|
|
initialValues,
|
|
|
|
configPath: 'instanceDetails',
|
2020-12-29 11:51:56 +01:00
|
|
|
};
|
2020-12-27 03:04:23 +01:00
|
|
|
|
|
|
|
return (
|
2021-01-27 10:46:08 +01:00
|
|
|
<>
|
2020-12-27 03:04:23 +01:00
|
|
|
<Title level={2}>Edit your public facing instance details</Title>
|
2020-12-28 10:11:26 +01:00
|
|
|
|
2021-01-27 10:46:08 +01:00
|
|
|
<div className={configStyles.publicDetailsContainer}>
|
|
|
|
<div className={configStyles.textFieldsSection}>
|
2020-12-28 10:11:26 +01:00
|
|
|
<Form
|
|
|
|
form={form}
|
|
|
|
layout="vertical"
|
|
|
|
>
|
2021-01-03 09:29:37 +01:00
|
|
|
<TextField
|
|
|
|
fieldName="instanceUrl"
|
|
|
|
{...extraProps}
|
|
|
|
configPath="yp"
|
2021-01-03 13:03:18 +01:00
|
|
|
type={TEXTFIELD_TYPE_URL}
|
2021-01-03 09:29:37 +01:00
|
|
|
onSubmit={handleSubmitInstanceUrl}
|
|
|
|
/>
|
|
|
|
|
2020-12-29 11:51:56 +01:00
|
|
|
<TextField fieldName="title" {...extraProps} />
|
|
|
|
<TextField fieldName="streamTitle" {...extraProps} />
|
2021-01-03 09:29:37 +01:00
|
|
|
<TextField fieldName="name" {...extraProps} />
|
|
|
|
<TextField fieldName="summary" type={TEXTFIELD_TYPE_TEXTAREA} {...extraProps} />
|
|
|
|
<TextField fieldName="logo" {...extraProps} />
|
2020-12-27 04:44:09 +01:00
|
|
|
</Form>
|
2021-01-03 10:54:04 +01:00
|
|
|
|
2021-01-27 10:46:08 +01:00
|
|
|
<Link href="/admin/config-page-content">
|
|
|
|
<a>Edit your extra page content here.</a>
|
|
|
|
</Link>
|
2020-12-27 03:04:23 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-01-27 10:46:08 +01:00
|
|
|
</>
|
2020-12-27 03:04:23 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-12-31 03:07:15 +01:00
|
|
|
|