Fakultas Ilmu Komputer UI

index.tsx 1.62 KB
Newer Older
1
2
import React, { FC } from 'react';
import { ScrollView, View } from 'react-native';
3
import { Text, Button } from 'react-native-elements';
4
5
import { WebView } from 'react-native-webview';

6
import { InfoCard, Loader, EmptyDataPage } from 'components/core';
7
import { layoutStyles } from 'styles';
8
import { useDownloadFiles } from 'hooks';
9
import { getAbsoluteUrl } from 'utils/format';
10
11

import { styles } from './styles';
12
import { Props } from './types';
13

14
15
const ReadOnlyDietRecommendation: FC<Props> = ({ children, data }) => {
  const { download, pdfViewUrl, fileName } = useDownloadFiles(
16
    getAbsoluteUrl(data?.client_plan_meal),
17
  );
18

19
  if (!data) {
20
    return <EmptyDataPage text="Belum ada rekomendasi dari nutritionis" />;
21
  }
22
23
24
  return (
    <ScrollView contentContainerStyle={layoutStyles}>
      <Text style={styles.header}>Saran Gizi</Text>
25
      <InfoCard content={data.nutritional_advice} />
26
      <Text style={[styles.header, styles.spacing]}>Saran Gaya Hidup</Text>
27
      <InfoCard content={data.lifestyle_advice} />
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
      <View style={styles.spacing}>
        <Text style={styles.header}>Rencana Menu dan Porsi Makan</Text>
      </View>
      <WebView
        source={{ uri: pdfViewUrl }}
        style={styles.pdfView}
        originWhitelist={['*']}
        renderLoading={Loader}
      />
      <Button
        title={`Unduh ${fileName}`}
        type="outline"
        icon={{
          name: 'file-download',
        }}
        iconRight
        buttonStyle={styles.buttonStyle}
        titleStyle={styles.titleStyle}
        onPress={download}
      />
      {children}
    </ScrollView>
  );
};

53
export default ReadOnlyDietRecommendation;