Application Android et IOS pour l'amicale des élèves https://play.google.com/store/apps/details?id=fr.amicaleinsat.application
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.js 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. // @flow
  20. import * as React from 'react';
  21. import i18n from 'i18n-js';
  22. import {ERROR_TYPE} from '../../utils/WebData';
  23. import AlertDialog from './AlertDialog';
  24. type PropsType = {
  25. visible: boolean,
  26. onDismiss: () => void,
  27. errorCode: number,
  28. };
  29. class ErrorDialog extends React.PureComponent<PropsType> {
  30. title: string;
  31. message: string;
  32. generateMessage() {
  33. const {props} = this;
  34. this.title = i18n.t('errors.title');
  35. switch (props.errorCode) {
  36. case ERROR_TYPE.BAD_CREDENTIALS:
  37. this.message = i18n.t('errors.badCredentials');
  38. break;
  39. case ERROR_TYPE.BAD_TOKEN:
  40. this.message = i18n.t('errors.badToken');
  41. break;
  42. case ERROR_TYPE.NO_CONSENT:
  43. this.message = i18n.t('errors.noConsent');
  44. break;
  45. case ERROR_TYPE.TOKEN_SAVE:
  46. this.message = i18n.t('errors.tokenSave');
  47. break;
  48. case ERROR_TYPE.TOKEN_RETRIEVE:
  49. this.message = i18n.t('errors.unknown');
  50. break;
  51. case ERROR_TYPE.BAD_INPUT:
  52. this.message = i18n.t('errors.badInput');
  53. break;
  54. case ERROR_TYPE.FORBIDDEN:
  55. this.message = i18n.t('errors.forbidden');
  56. break;
  57. case ERROR_TYPE.CONNECTION_ERROR:
  58. this.message = i18n.t('errors.connectionError');
  59. break;
  60. case ERROR_TYPE.SERVER_ERROR:
  61. this.message = i18n.t('errors.serverError');
  62. break;
  63. default:
  64. this.message = i18n.t('errors.unknown');
  65. break;
  66. }
  67. this.message += `\n\nCode ${props.errorCode}`;
  68. }
  69. render(): React.Node {
  70. this.generateMessage();
  71. const {props} = this;
  72. return (
  73. <AlertDialog
  74. visible={props.visible}
  75. onDismiss={props.onDismiss}
  76. title={this.title}
  77. message={this.message}
  78. />
  79. );
  80. }
  81. }
  82. export default ErrorDialog;