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.

ProxiwashSettingsScreen.js 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. // @flow
  2. import * as React from 'react';
  3. import {
  4. Title,
  5. Button,
  6. Card,
  7. Avatar,
  8. withTheme,
  9. Paragraph,
  10. } from 'react-native-paper';
  11. import i18n from 'i18n-js';
  12. import CollapsibleScrollView from '../../components/Collapsible/CollapsibleScrollView';
  13. import type {CardTitleIconPropsType} from '../../constants/PaperStyles';
  14. import AsyncStorageManager from '../../managers/AsyncStorageManager';
  15. import ThemeManager from '../../managers/ThemeManager';
  16. import type {CustomThemeType} from '../../managers/ThemeManager';
  17. export type LaverieType = {
  18. id: string,
  19. title: string,
  20. subtitle: string,
  21. description: string,
  22. tarif: string,
  23. paymentMethods: string,
  24. icon: string,
  25. url: string,
  26. };
  27. export const PROXIWASH_DATA = {
  28. washinsa: {
  29. id: 'washinsa',
  30. title: i18n.t('screens.proxiwash.washinsa.title'),
  31. subtitle: i18n.t('screens.proxiwash.washinsa.subtitle'),
  32. description: i18n.t('screens.proxiwash.washinsa.description'),
  33. tarif: i18n.t('screens.proxiwash.washinsa.tariff'),
  34. paymentMethods: i18n.t('screens.proxiwash.washinsa.paymentMethods'),
  35. icon: 'school-outline',
  36. url:
  37. 'https://etud.insa-toulouse.fr/~amicale_app/v2/washinsa/washinsa_data.json',
  38. },
  39. tripodeB: {
  40. id: 'tripodeB',
  41. title: i18n.t('screens.proxiwash.tripodeB.title'),
  42. subtitle: i18n.t('screens.proxiwash.tripodeB.subtitle'),
  43. description: i18n.t('screens.proxiwash.tripodeB.description'),
  44. tarif: i18n.t('screens.proxiwash.tripodeB.tariff'),
  45. paymentMethods: i18n.t('screens.proxiwash.tripodeB.paymentMethods'),
  46. icon: 'domain',
  47. url:
  48. 'https://etud.insa-toulouse.fr/~amicale_app/v2/washinsa/tripode_b_data.json',
  49. },
  50. };
  51. type StateType = {
  52. selectedWash: string,
  53. currentTheme: CustomThemeType,
  54. };
  55. /**
  56. * Class defining the proxiwash settings screen.
  57. */
  58. class ProxiwashSettingsScreen extends React.Component<null, StateType> {
  59. constructor() {
  60. super();
  61. this.state = {
  62. selectedWash: AsyncStorageManager.getString(
  63. AsyncStorageManager.PREFERENCES.selectedWash.key,
  64. ),
  65. };
  66. }
  67. /**
  68. * Saves the value for the proxiwash reminder notification time
  69. *
  70. * @param value The value to store
  71. */
  72. onSelectWashValueChange = (value: string) => {
  73. if (value != null) {
  74. this.setState({selectedWash: value});
  75. AsyncStorageManager.set(
  76. AsyncStorageManager.PREFERENCES.selectedWash.key,
  77. value,
  78. );
  79. }
  80. };
  81. getCardItem(item: LaverieType): React.Node {
  82. const {selectedWash} = this.state;
  83. const onSelectWashValueChange = (): void =>
  84. this.onSelectWashValueChange(item.id);
  85. let cardStyle = {
  86. margin: 5,
  87. };
  88. if (selectedWash === item.id) {
  89. cardStyle = {
  90. margin: 5,
  91. backgroundColor: ThemeManager.getCurrentTheme().colors
  92. .proxiwashUnknownColor,
  93. };
  94. }
  95. return (
  96. <Card style={cardStyle}>
  97. <Card.Title
  98. title={item.title}
  99. subtitle={item.subtitle}
  100. left={(iconProps: CardTitleIconPropsType): React.Node => (
  101. <Avatar.Icon size={iconProps.size} icon={item.icon} />
  102. )}
  103. />
  104. <Card.Content>
  105. <Paragraph>{item.description}</Paragraph>
  106. <Title>{i18n.t('screens.proxiwash.tariffs')}</Title>
  107. <Paragraph>{item.tarif}</Paragraph>
  108. <Title>{i18n.t('screens.proxiwash.paymentMethods')}</Title>
  109. <Paragraph>{item.paymentMethods}</Paragraph>
  110. </Card.Content>
  111. <Card.Actions>
  112. <Button onPress={onSelectWashValueChange}>Select</Button>
  113. </Card.Actions>
  114. </Card>
  115. );
  116. }
  117. render(): React.Node {
  118. return (
  119. <CollapsibleScrollView style={{padding: 5}} hasTab>
  120. {this.getCardItem(PROXIWASH_DATA.washinsa)}
  121. {this.getCardItem(PROXIWASH_DATA.tripodeB)}
  122. </CollapsibleScrollView>
  123. );
  124. }
  125. }
  126. export default withTheme(ProxiwashSettingsScreen);