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.

EquipmentConfirmScreen.js 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 {
  22. Button,
  23. Caption,
  24. Card,
  25. Headline,
  26. Paragraph,
  27. withTheme,
  28. } from 'react-native-paper';
  29. import {View} from 'react-native';
  30. import i18n from 'i18n-js';
  31. import type {CustomThemeType} from '../../../managers/ThemeManager';
  32. import type {DeviceType} from './EquipmentListScreen';
  33. import {getRelativeDateString} from '../../../utils/EquipmentBooking';
  34. import CollapsibleScrollView from '../../../components/Collapsible/CollapsibleScrollView';
  35. type PropsType = {
  36. route: {
  37. params?: {
  38. item?: DeviceType,
  39. dates: [string, string],
  40. },
  41. },
  42. theme: CustomThemeType,
  43. };
  44. class EquipmentConfirmScreen extends React.Component<PropsType> {
  45. item: DeviceType | null;
  46. dates: [string, string] | null;
  47. constructor(props: PropsType) {
  48. super(props);
  49. if (props.route.params != null) {
  50. if (props.route.params.item != null) this.item = props.route.params.item;
  51. else this.item = null;
  52. if (props.route.params.dates != null)
  53. this.dates = props.route.params.dates;
  54. else this.dates = null;
  55. }
  56. }
  57. render(): React.Node {
  58. const {item, dates, props} = this;
  59. if (item != null && dates != null) {
  60. const start = new Date(dates[0]);
  61. const end = new Date(dates[1]);
  62. let buttonText;
  63. if (start == null) buttonText = i18n.t('screens.equipment.booking');
  64. else if (end != null && start.getTime() !== end.getTime())
  65. buttonText = i18n.t('screens.equipment.bookingPeriod', {
  66. begin: getRelativeDateString(start),
  67. end: getRelativeDateString(end),
  68. });
  69. else
  70. buttonText = i18n.t('screens.equipment.bookingDay', {
  71. date: getRelativeDateString(start),
  72. });
  73. return (
  74. <CollapsibleScrollView>
  75. <Card style={{margin: 5}}>
  76. <Card.Content>
  77. <View style={{flex: 1}}>
  78. <View
  79. style={{
  80. marginLeft: 'auto',
  81. marginRight: 'auto',
  82. flexDirection: 'row',
  83. flexWrap: 'wrap',
  84. }}>
  85. <Headline style={{textAlign: 'center'}}>{item.name}</Headline>
  86. <Caption
  87. style={{
  88. textAlign: 'center',
  89. lineHeight: 35,
  90. marginLeft: 10,
  91. }}>
  92. ({i18n.t('screens.equipment.bail', {cost: item.caution})})
  93. </Caption>
  94. </View>
  95. </View>
  96. <Button
  97. icon="check-circle-outline"
  98. color={props.theme.colors.success}
  99. mode="text">
  100. {buttonText}
  101. </Button>
  102. <Paragraph style={{textAlign: 'center'}}>
  103. {i18n.t('screens.equipment.bookingConfirmedMessage')}
  104. </Paragraph>
  105. </Card.Content>
  106. </Card>
  107. </CollapsibleScrollView>
  108. );
  109. }
  110. return null;
  111. }
  112. }
  113. export default withTheme(EquipmentConfirmScreen);