Application Android et IOS pour l'amicale des élèves
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ErrorDialog.tsx 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Copyright (c) 2019 - 2020 Arnaud Vergnet.
  3. *
  4. * This file is part of Campus INSAT.
  5. *
  6. * Campus INSAT is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Campus INSAT is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Campus INSAT. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. import * as React from 'react';
  20. import i18n from 'i18n-js';
  21. import {ERROR_TYPE} from '../../utils/WebData';
  22. import AlertDialog from './AlertDialog';
  23. type PropsType = {
  24. visible: boolean;
  25. onDismiss: () => void;
  26. errorCode: number;
  27. };
  28. function ErrorDialog(props: PropsType) {
  29. let title: string;
  30. let message: string;
  31. title = i18n.t('errors.title');
  32. switch (props.errorCode) {
  33. case ERROR_TYPE.BAD_CREDENTIALS:
  34. message = i18n.t('errors.badCredentials');
  35. break;
  36. case ERROR_TYPE.BAD_TOKEN:
  37. message = i18n.t('errors.badToken');
  38. break;
  39. case ERROR_TYPE.NO_CONSENT:
  40. message = i18n.t('errors.noConsent');
  41. break;
  42. case ERROR_TYPE.TOKEN_SAVE:
  43. message = i18n.t('errors.tokenSave');
  44. break;
  45. case ERROR_TYPE.TOKEN_RETRIEVE:
  46. message = i18n.t('errors.unknown');
  47. break;
  48. case ERROR_TYPE.BAD_INPUT:
  49. message = i18n.t('errors.badInput');
  50. break;
  51. case ERROR_TYPE.FORBIDDEN:
  52. message = i18n.t('errors.forbidden');
  53. break;
  54. case ERROR_TYPE.CONNECTION_ERROR:
  55. message = i18n.t('errors.connectionError');
  56. break;
  57. case ERROR_TYPE.SERVER_ERROR:
  58. message = i18n.t('errors.serverError');
  59. break;
  60. default:
  61. message = i18n.t('errors.unknown');
  62. break;
  63. }
  64. message += `\n\nCode ${props.errorCode}`;
  65. return (
  66. <AlertDialog
  67. visible={props.visible}
  68. onDismiss={props.onDismiss}
  69. title={title}
  70. message={message}
  71. />
  72. );
  73. }
  74. export default ErrorDialog;