overview.tsx 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import React, { useContext, useState } from 'react';
  2. import { Button } from 'primereact/button';
  3. import { Card } from 'primereact/card';
  4. import { DataTable } from 'primereact/datatable';
  5. import { Password } from 'primereact/password';
  6. import { AuthContext } from '../contexts';
  7. import { Auth, Session } from '../services';
  8. import { BackendReturnStatus } from '../types';
  9. import { Column } from 'primereact/column';
  10. export const Overview: React.FC = () => {
  11. const [statusMessage, setStatusMessage] = useState<{ error: boolean; message: string }>({
  12. error: false,
  13. message: '',
  14. });
  15. const { auth, reloadAuth } = useContext(AuthContext);
  16. const regenerateKey = async () => {
  17. Auth.refreshRadarScopeKey().then((status) => {
  18. if (status === BackendReturnStatus.Unauthorized) {
  19. Session.setLastShownComponent('/overview');
  20. Auth.triggerLoginFlow();
  21. } else if (status === BackendReturnStatus.Failure) {
  22. setStatusMessage({
  23. error: true,
  24. message: 'Unable to regenerate the key',
  25. });
  26. } else {
  27. reloadAuth();
  28. setStatusMessage({
  29. error: false,
  30. message: 'Updated the key',
  31. });
  32. }
  33. });
  34. }
  35. const userInformation: any[] = [
  36. { vatsimId: auth.user.vatsimId, fullName: auth.user.fullName !== '' ? auth.user.fullName : 'Unknown' },
  37. ];
  38. const userData = (
  39. <>
  40. <div>
  41. <DataTable value={userInformation} showGridlines>
  42. <Column field='vatsimId' header='VATSIM ID'></Column>
  43. <Column field='fullName' header='Name'></Column>
  44. </DataTable>
  45. </div>
  46. <div>
  47. <h4>RADAR scope key</h4>
  48. <Password
  49. value={auth.user.radarScopeKey}
  50. className='mr-3'
  51. feedback={false}
  52. toggleMask
  53. />
  54. <Button
  55. label='Regenerate'
  56. className='p-button-outlined p-button-secondary'
  57. onClick={regenerateKey}
  58. />
  59. <div className={statusMessage.error ? 'text-red-500' : 'text-secondary'}>
  60. {statusMessage.message}
  61. </div>
  62. </div>
  63. </>
  64. );
  65. const initialSteps = (
  66. <ul>
  67. <li>Download current Euroscope plugin version</li>
  68. <li>Add plugin to your Euroscope installation</li>
  69. <li>Copy 'RADAR Scope key'</li>
  70. <li>Paste the key into the amankey.txt file next to AMAN.dll of the Euroscope installation</li>
  71. <li>Restart Euroscope</li>
  72. <li>Activate AMAN plugin in Euroscpe</li>
  73. </ul>
  74. )
  75. return (
  76. <>
  77. <div className='card flex align-items-top justify-content-start p-3'>
  78. <Card
  79. title='Controller data'
  80. className='text-left surface-100 w-18.5rem h-21rem flex mr-3'
  81. footer={userData}
  82. />
  83. <Card
  84. title='Installation steps for Euroscope'
  85. className='text-left surface-100 w-42.5rem h-17rem flex mr-3'
  86. footer={initialSteps}
  87. />
  88. </div>
  89. </>
  90. );
  91. };