Fakultas Ilmu Komputer UI

Commit d44b5a68 authored by Wulan Mantiri's avatar Wulan Mantiri
Browse files

Merge branch 'PBI-11-fix_download_pdf' into 'staging'

Fix download pdf bug in diet recommendation

See merge request !70
parents 3a97f15b d7be3adb
Pipeline #80829 passed with stages
in 38 minutes and 11 seconds
...@@ -28,7 +28,7 @@ const useDownloadFiles = ( ...@@ -28,7 +28,7 @@ const useDownloadFiles = (
useDownloadManager: true, useDownloadManager: true,
notification: true, notification: true,
mime: fileType, mime: fileType,
title: 'Downloading ' + title + '...', title: 'Mengunduh ' + title + '...',
mediaScannable: true, mediaScannable: true,
path: dirs.DownloadDir + `/${fileName}`, path: dirs.DownloadDir + `/${fileName}`,
}, },
...@@ -42,7 +42,6 @@ const useDownloadFiles = ( ...@@ -42,7 +42,6 @@ const useDownloadFiles = (
fileName, fileName,
extension, extension,
download, download,
pdfViewUrl: `http://docs.google.com/gview?embedded=true&url=${url}`,
}; };
}; };
......
...@@ -10,6 +10,38 @@ describe('ReadOnlyDietRecommendation', () => { ...@@ -10,6 +10,38 @@ describe('ReadOnlyDietRecommendation', () => {
expect(getByText(/Belum ada rekomendasi/i)).toBeTruthy(); expect(getByText(/Belum ada rekomendasi/i)).toBeTruthy();
}); });
it('shows default no input text if recommendation is not fully provided yet', () => {
const { getByText } = render(
<ReadOnlyDietRecommendation
data={{
id: 1,
nutritionist: 1,
client: 1,
client_plan_meal: null,
nutritional_advice: '',
lifestyle_advice: 'hai',
}}
/>,
);
expect(getByText(/Belum ada nih, ditunggu yaa/i)).toBeTruthy();
});
it('shows default no input text if recommendation is not fully provided yet (2)', () => {
const { getByText } = render(
<ReadOnlyDietRecommendation
data={{
id: 1,
nutritionist: 1,
client: 1,
client_plan_meal: null,
nutritional_advice: 'bye',
lifestyle_advice: '',
}}
/>,
);
expect(getByText(/-/i)).toBeTruthy();
});
it('shows recommendation when provided', () => { it('shows recommendation when provided', () => {
const { getByText } = render( const { getByText } = render(
<ReadOnlyDietRecommendation data={mockDietRecommendation} />, <ReadOnlyDietRecommendation data={mockDietRecommendation} />,
......
import React, { FC } from 'react'; import React, { FC } from 'react';
import { ScrollView, View } from 'react-native'; import { ScrollView, View } from 'react-native';
import { Text, Button } from 'react-native-elements'; import { Text, Button } from 'react-native-elements';
import { WebView } from 'react-native-webview'; import Pdf from 'react-native-pdf';
import { InfoCard, Loader, EmptyDataPage } from 'components/core'; import { InfoCard, EmptyDataPage } from 'components/core';
import { layoutStyles } from 'styles'; import { layoutStyles } from 'styles';
import { useDownloadFiles } from 'hooks'; import { useDownloadFiles } from 'hooks';
import { DietRecommendationResponse } from 'services/dietRecommendation/models';
import { FileType } from 'hooks/useDownloadFiles/schema';
import { API_BASE_URL } from 'env';
import { styles } from './styles'; import { styles } from './styles';
import { Props } from './types'; import { Props } from './types';
import { DietRecommendationResponse } from 'services/dietRecommendation/models';
import { FileType } from 'hooks/useDownloadFiles/schema';
const ReadOnlyDietRecommendation: FC<Props> = ({ children, data }) => { const ReadOnlyDietRecommendation: FC<Props> = ({ children, data }) => {
const { download, pdfViewUrl, fileName } = useDownloadFiles( const url = API_BASE_URL + data?.client_plan_meal;
data?.client_plan_meal, const { download, fileName } = useDownloadFiles(
'diet recommendation', url,
'rencana makan',
FileType.PDF, FileType.PDF,
); );
...@@ -36,30 +38,30 @@ const ReadOnlyDietRecommendation: FC<Props> = ({ children, data }) => { ...@@ -36,30 +38,30 @@ const ReadOnlyDietRecommendation: FC<Props> = ({ children, data }) => {
return ( return (
<ScrollView contentContainerStyle={layoutStyles}> <ScrollView contentContainerStyle={layoutStyles}>
<Text style={styles.header}>Saran Gizi</Text> <Text style={styles.header}>Saran Gizi</Text>
<InfoCard content={data.nutritional_advice} /> <InfoCard content={data.nutritional_advice || '-'} />
<Text style={[styles.header, styles.spacing]}>Saran Gaya Hidup</Text> <Text style={[styles.header, styles.spacing]}>Saran Gaya Hidup</Text>
<InfoCard content={data.lifestyle_advice} /> <InfoCard content={data.lifestyle_advice || '-'} />
<View style={styles.spacing}> <View style={styles.spacing}>
<Text style={styles.header}>Rencana Menu dan Porsi Makan</Text> <Text style={styles.header}>Rencana Menu dan Porsi Makan</Text>
</View> </View>
<WebView {data?.client_plan_meal ? (
source={{ uri: pdfViewUrl }} <View>
style={styles.pdfView} <Pdf source={{ uri: url, cache: true }} style={styles.pdfView} />
originWhitelist={['*']} <Button
showsVerticalScrollIndicator={false} title={`Unduh ${fileName}`}
renderLoading={Loader} type="outline"
/> icon={{
<Button name: 'file-download',
title={`Unduh ${fileName}`} }}
type="outline" iconRight
icon={{ buttonStyle={styles.buttonStyle}
name: 'file-download', titleStyle={styles.titleStyle}
}} onPress={download}
iconRight />
buttonStyle={styles.buttonStyle} </View>
titleStyle={styles.titleStyle} ) : (
onPress={download} <InfoCard content="Belum ada nih, ditunggu yaa" />
/> )}
{children} {children}
</ScrollView> </ScrollView>
); );
......
...@@ -11,8 +11,8 @@ export const styles = StyleSheet.create({ ...@@ -11,8 +11,8 @@ export const styles = StyleSheet.create({
marginTop: 20, marginTop: 20,
}, },
pdfView: { pdfView: {
height: Dimensions.get('window').height * 0.6, height: Dimensions.get('window').height * 0.75,
marginBottom: 10, marginBottom: 8,
}, },
buttonStyle: { buttonStyle: {
backgroundColor: colors.primaryYellow, backgroundColor: colors.primaryYellow,
......
export interface DietRecommendationResponse { export interface DietRecommendationResponse {
id: number; id: number;
client_plan_meal: string; client_plan_meal: string | null;
nutritional_advice: string; nutritional_advice: string;
lifestyle_advice: string; lifestyle_advice: string;
nutritionist: number; nutritionist: number;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment