2021-02-13 10:55:59 +03:00
|
|
|
import { Popconfirm, Button, Typography } from 'antd';
|
2022-09-07 10:00:28 +03:00
|
|
|
import { FC, useContext, useState } from 'react';
|
2021-02-13 10:55:59 +03:00
|
|
|
import { AlertMessageContext } from '../../utils/alert-message-context';
|
|
|
|
|
|
|
|
import { API_YP_RESET, fetchData } from '../../utils/apis';
|
2021-02-15 11:08:52 +03:00
|
|
|
import { RESET_TIMEOUT } from '../../utils/config-constants';
|
|
|
|
import {
|
|
|
|
createInputStatus,
|
|
|
|
STATUS_ERROR,
|
|
|
|
STATUS_PROCESSING,
|
|
|
|
STATUS_SUCCESS,
|
|
|
|
} from '../../utils/input-statuses';
|
2022-09-07 10:00:28 +03:00
|
|
|
import { FormStatusIndicator } from './FormStatusIndicator';
|
2021-02-13 10:55:59 +03:00
|
|
|
|
2022-09-07 10:00:28 +03:00
|
|
|
export const ResetYP: FC = () => {
|
2021-02-13 10:55:59 +03:00
|
|
|
const { setMessage } = useContext(AlertMessageContext);
|
|
|
|
|
2021-02-15 11:08:52 +03:00
|
|
|
const [submitStatus, setSubmitStatus] = useState(null);
|
|
|
|
let resetTimer = null;
|
|
|
|
const resetStates = () => {
|
|
|
|
setSubmitStatus(null);
|
|
|
|
resetTimer = null;
|
|
|
|
clearTimeout(resetTimer);
|
|
|
|
};
|
2021-02-13 10:55:59 +03:00
|
|
|
|
|
|
|
const resetDirectoryRegistration = async () => {
|
2021-02-15 11:08:52 +03:00
|
|
|
setSubmitStatus(createInputStatus(STATUS_PROCESSING));
|
2021-02-13 10:55:59 +03:00
|
|
|
try {
|
|
|
|
await fetchData(API_YP_RESET);
|
|
|
|
setMessage('');
|
2021-02-15 11:08:52 +03:00
|
|
|
setSubmitStatus(createInputStatus(STATUS_SUCCESS));
|
|
|
|
resetTimer = setTimeout(resetStates, RESET_TIMEOUT);
|
2021-02-13 10:55:59 +03:00
|
|
|
} catch (error) {
|
2021-02-15 11:08:52 +03:00
|
|
|
setSubmitStatus(createInputStatus(STATUS_ERROR, `There was an error: ${error}`));
|
|
|
|
resetTimer = setTimeout(resetStates, RESET_TIMEOUT);
|
2021-02-13 10:55:59 +03:00
|
|
|
}
|
|
|
|
};
|
2021-02-15 11:08:52 +03:00
|
|
|
|
2021-02-13 10:55:59 +03:00
|
|
|
return (
|
|
|
|
<>
|
2021-02-15 11:08:52 +03:00
|
|
|
<Typography.Title level={3} className="section-title">
|
2021-02-13 10:55:59 +03:00
|
|
|
Reset Directory
|
2021-02-15 11:08:52 +03:00
|
|
|
</Typography.Title>
|
2021-02-13 10:55:59 +03:00
|
|
|
<p className="description">
|
|
|
|
If you are experiencing issues with your listing on the Owncast Directory and were asked to
|
|
|
|
"reset" your connection to the service, you can do that here. The next time you go
|
|
|
|
live it will try and re-register your server with the directory from scratch.
|
|
|
|
</p>
|
|
|
|
|
|
|
|
<Popconfirm
|
|
|
|
placement="topLeft"
|
|
|
|
title="Are you sure you want to reset your connection to the Owncast directory?"
|
|
|
|
onConfirm={resetDirectoryRegistration}
|
|
|
|
okText="Yes"
|
|
|
|
cancelText="No"
|
|
|
|
>
|
|
|
|
<Button type="primary">Reset Directory Connection</Button>
|
|
|
|
</Popconfirm>
|
2021-02-15 11:08:52 +03:00
|
|
|
<p>
|
|
|
|
<FormStatusIndicator status={submitStatus} />
|
|
|
|
</p>
|
2021-02-13 10:55:59 +03:00
|
|
|
</>
|
|
|
|
);
|
2022-09-07 10:00:28 +03:00
|
|
|
};
|