Files
pterodactyl-panel/resources/scripts/components/server/features/GSLTokenModalFeature.tsx
T

78 lines
3.0 KiB
TypeScript
Raw Normal View History

2026-10-05 18:10:18 -04:00
import { useSocketInstance } from '@/state/server';
import { Dialog } from '@/components/elements/dialog';
import SpinnerOverlay from '@/components/elements/SpinnerOverlay';
import { SocketRequest } from '@/components/server/events';
import { useAppForm, Form } from '@/components/form';
import { useCurrentServerUuid } from '@/api/server/queries';
import { useUpdateStartupVariable } from '@/api/server/startup/queries';
import { useConsolePatternTrigger } from '@/components/server/features/useConsolePatternTrigger';
2021-12-04 19:29:24 +01:00
2026-10-05 18:10:18 -04:00
const gslTokenErrors = ['(gsl token expired)', '(account not found)'];
2021-12-04 19:29:24 +01:00
const GSLTokenModalFeature = () => {
2026-10-05 18:10:18 -04:00
const dialog = useConsolePatternTrigger(gslTokenErrors);
2021-12-04 19:29:24 +01:00
2026-10-05 18:10:18 -04:00
const uuid = useCurrentServerUuid()!;
const instance = useSocketInstance();
const updateVariable = useUpdateStartupVariable(uuid);
const loading = updateVariable.isPending;
2021-12-04 19:29:24 +01:00
2026-10-05 18:10:18 -04:00
const form = useAppForm({
defaultValues: { gslToken: '' },
onSubmit: async ({ value }) => {
try {
await updateVariable.mutateAsync({
path: { server_uuid: uuid },
body: { key: 'STEAM_ACC', value: value.gslToken },
});
2021-12-04 19:29:24 +01:00
if (instance) {
instance.send(SocketRequest.SET_STATE, 'restart');
}
2026-10-05 18:10:18 -04:00
dialog.hide();
} catch {
// Error toast is handled by the mutation.
}
},
});
2021-12-04 19:29:24 +01:00
return (
2026-10-05 18:10:18 -04:00
<Dialog
open={dialog.open}
2026-10-08 16:53:20 -04:00
title='Invalid GSL token'
2026-10-05 18:10:18 -04:00
onClose={dialog.hide}
preventExternalClose={loading}
hideCloseIcon={loading}
>
<SpinnerOverlay visible={loading} />
<Form form={form}>
2026-10-08 16:53:20 -04:00
<p className='mt-4'>It seems like your Gameserver Login Token (GSL token) is invalid or has expired.</p>
<p className='mt-4'>
2026-10-05 18:10:18 -04:00
You can either generate a new one and enter it below or leave the field blank to remove it
completely.
</p>
2026-10-08 16:53:20 -04:00
<div className='sm:flex items-center mt-4'>
<form.AppField name='gslToken'>
2026-10-05 18:10:18 -04:00
{(field) => (
<field.TextField
2026-10-08 16:53:20 -04:00
label='GSL Token'
description='Visit https://steamcommunity.com/dev/managegameservers to generate a token.'
2026-10-05 18:10:18 -04:00
autoFocus
/>
)}
</form.AppField>
</div>
2026-10-08 16:53:20 -04:00
<div className='mt-8 sm:flex items-center justify-end'>
<div className='mt-4 sm:mt-0 sm:ml-4 w-full sm:w-auto'>
2026-10-05 18:10:18 -04:00
<form.AppForm>
2026-10-08 16:53:20 -04:00
<form.SubmitButton className='w-full sm:w-auto'>Update GSL Token</form.SubmitButton>
2026-10-05 18:10:18 -04:00
</form.AppForm>
2021-12-04 19:29:24 +01:00
</div>
2026-10-05 18:10:18 -04:00
</div>
</Form>
</Dialog>
2021-12-04 19:29:24 +01:00
);
};
export default GSLTokenModalFeature;