mirror of
				https://github.com/owncast/owncast.git
				synced 2025-10-31 18:18:06 +08:00 
			
		
		
		
	 383b80851b
			
		
	
	383b80851b
	
	
	
		
			
			* Initial plan * Add localization support to admin form status and error messages Co-authored-by: gabek <414923+gabek@users.noreply.github.com> * Format updated files with prettier Co-authored-by: gabek <414923+gabek@users.noreply.github.com> * Replace t() with Translation component in admin page JSX Co-authored-by: gabek <414923+gabek@users.noreply.github.com> * update package-lock.json * Update web/i18n/en/translation.json Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: gabek <414923+gabek@users.noreply.github.com> Co-authored-by: Gabe Kangas <gabek@real-ity.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
		
			
				
	
	
		
			74 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			74 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| import { Popconfirm, Button, Typography } from 'antd';
 | |
| import { FC, useContext, useState } from 'react';
 | |
| import { useTranslation } from 'next-export-i18n';
 | |
| import { AlertMessageContext } from '../../utils/alert-message-context';
 | |
| 
 | |
| import { API_YP_RESET, fetchData } from '../../utils/apis';
 | |
| import { RESET_TIMEOUT } from '../../utils/config-constants';
 | |
| import {
 | |
|   createInputStatus,
 | |
|   STATUS_ERROR,
 | |
|   STATUS_PROCESSING,
 | |
|   STATUS_SUCCESS,
 | |
| } from '../../utils/input-statuses';
 | |
| import { Localization } from '../../types/localization';
 | |
| import { FormStatusIndicator } from './FormStatusIndicator';
 | |
| 
 | |
| // eslint-disable-next-line import/prefer-default-export
 | |
| export const ResetYP: FC = () => {
 | |
|   const { t } = useTranslation();
 | |
|   const { setMessage } = useContext(AlertMessageContext);
 | |
| 
 | |
|   const [submitStatus, setSubmitStatus] = useState(null);
 | |
|   let resetTimer = null;
 | |
|   const resetStates = () => {
 | |
|     setSubmitStatus(null);
 | |
|     resetTimer = null;
 | |
|     clearTimeout(resetTimer);
 | |
|   };
 | |
| 
 | |
|   const resetDirectoryRegistration = async () => {
 | |
|     setSubmitStatus(createInputStatus(STATUS_PROCESSING));
 | |
|     try {
 | |
|       await fetchData(API_YP_RESET);
 | |
|       setMessage('');
 | |
|       setSubmitStatus(createInputStatus(STATUS_SUCCESS));
 | |
|       resetTimer = setTimeout(resetStates, RESET_TIMEOUT);
 | |
|     } catch (error) {
 | |
|       setSubmitStatus(
 | |
|         createInputStatus(
 | |
|           STATUS_ERROR,
 | |
|           t(Localization.Admin.StatusMessages.thereWasAnError, { message: `${error}` }),
 | |
|         ),
 | |
|       );
 | |
|       resetTimer = setTimeout(resetStates, RESET_TIMEOUT);
 | |
|     }
 | |
|   };
 | |
| 
 | |
|   return (
 | |
|     <>
 | |
|       <Typography.Title level={3} className="section-title">
 | |
|         Reset Directory
 | |
|       </Typography.Title>
 | |
|       <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>
 | |
|       <p>
 | |
|         <FormStatusIndicator status={submitStatus} />
 | |
|       </p>
 | |
|     </>
 | |
|   );
 | |
| };
 |