Fakultas Ilmu Komputer UI

Commit 7155e4dd authored by Kefas Satrio Bangkit Solidedantyo's avatar Kefas Satrio Bangkit Solidedantyo
Browse files

Merge branch 'PBI-9-read-diet-profile' into 'staging'

Handle null data for diet profile page

See merge request !51
parents dcf7a98b a8eef02c
Pipeline #76683 passed with stages
in 60 minutes and 15 seconds
import React from 'react';
import { render } from '@testing-library/react-native';
import EmptyDataPage from '.';
describe('EmptyDataPage', () => {
it('renders correctly', () => {
render(<EmptyDataPage text="No data" />);
});
});
import React, { FC } from 'react';
import { styles } from './styles';
import { View } from 'react-native';
import { Text, Icon } from 'react-native-elements';
import { colors } from 'styles';
interface Props {
text: string;
}
const EmptyDataPage: FC<Props> = ({ text }) => (
<View style={styles.center}>
<Icon
name="emoticon-sad-outline"
type="material-community"
size={75}
color={colors.danger}
/>
<Text style={styles.noRecomText}>{text}</Text>
</View>
);
export default EmptyDataPage;
import { StyleSheet } from 'react-native';
import { typography } from 'styles';
export const styles = StyleSheet.create({
center: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
paddingHorizontal: 30,
},
noRecomText: {
...typography.headingMedium,
textAlign: 'center',
marginTop: 10,
},
});
import { useState, useEffect, useCallback } from 'react'; import { useState, useEffect, useCallback } from 'react';
import { ApiResponse, Response } from 'services/api'; import { ApiResponse, Response } from 'services/api';
import { Toast } from 'components/core';
const useApi = <T>( const useApi = <T>(
fetchApi: () => ApiResponse<T>, fetchApi: () => ApiResponse<T>,
): { ): {
...@@ -18,14 +16,6 @@ const useApi = <T>( ...@@ -18,14 +16,6 @@ const useApi = <T>(
useEffect(() => { useEffect(() => {
const fetchData = async () => { const fetchData = async () => {
const apiResponse = await fetchApiWrapper(); const apiResponse = await fetchApiWrapper();
console.log(apiResponse);
if (!apiResponse.success) {
Toast.show({
type: 'error',
text1: 'Gagal memuat data',
text2: 'Terjadi kesalahan pada sisi kami.',
});
}
setResponse({ setResponse({
isLoading: false, isLoading: false,
...apiResponse, ...apiResponse,
......
...@@ -11,4 +11,14 @@ describe('ReadOnlyDietProfile', () => { ...@@ -11,4 +11,14 @@ describe('ReadOnlyDietProfile', () => {
routeParams: mockDietQuestionnaire, routeParams: mockDietQuestionnaire,
}); });
}); });
it('shows "Klien belum mengisi diet questionnaire" text if no questionnaire answer is provided yet', () => {
const { getByText } = render(
<ReadOnlyDietProfile />,
ROUTES.clientProfileNutritionist,
{
routeParams: { id: null },
},
);
expect(getByText(/Klien belum mengisi diet questionnaire/i)).toBeTruthy();
});
}); });
...@@ -11,6 +11,7 @@ import { pages } from './pages'; ...@@ -11,6 +11,7 @@ import { pages } from './pages';
import { useApi } from 'hooks'; import { useApi } from 'hooks';
import { retrieveDietQuestionnaireByIdApi } from 'services/dietQuestionnaire'; import { retrieveDietQuestionnaireByIdApi } from 'services/dietQuestionnaire';
import { DietQuestionnaireResponse } from 'services/dietQuestionnaire/models'; import { DietQuestionnaireResponse } from 'services/dietQuestionnaire/models';
import EmptyDataPage from 'components/core/EmptyDataPage';
interface QuestionnaireID { interface QuestionnaireID {
id: number; id: number;
...@@ -24,6 +25,10 @@ const ReadOnlyDietProfile: FC = () => { ...@@ -24,6 +25,10 @@ const ReadOnlyDietProfile: FC = () => {
retrieveDietQuestionnaireByIdApi(id), retrieveDietQuestionnaireByIdApi(id),
); );
if (!id) {
return <EmptyDataPage text="Klien belum mengisi diet questionnaire" />;
}
if (isLoading) { if (isLoading) {
return <Loader />; return <Loader />;
} }
......
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, Icon } from 'react-native-elements'; import { Text, Button } from 'react-native-elements';
import { WebView } from 'react-native-webview'; import { WebView } from 'react-native-webview';
import { InfoCard, Loader } from 'components/core'; import { InfoCard, Loader } from 'components/core';
import { layoutStyles, colors } from 'styles'; import { layoutStyles } from 'styles';
import { useDownloadFiles } from 'hooks'; import { useDownloadFiles } from 'hooks';
import { getAbsoluteUrl } from 'utils/format'; import { getAbsoluteUrl } from 'utils/format';
import { styles } from './styles'; import { styles } from './styles';
import { Props } from './types'; import { Props } from './types';
import EmptyDataPage from 'components/core/EmptyDataPage';
const ReadOnlyDietRecommendation: FC<Props> = ({ children, data }) => { const ReadOnlyDietRecommendation: FC<Props> = ({ children, data }) => {
const { download, pdfViewUrl, fileName } = useDownloadFiles( const { download, pdfViewUrl, fileName } = useDownloadFiles(
...@@ -17,19 +18,7 @@ const ReadOnlyDietRecommendation: FC<Props> = ({ children, data }) => { ...@@ -17,19 +18,7 @@ const ReadOnlyDietRecommendation: FC<Props> = ({ children, data }) => {
); );
if (!data) { if (!data) {
return ( return <EmptyDataPage text="Belum ada rekomendasi dari nutritionis" />;
<View style={styles.center}>
<Icon
name="emoticon-sad-outline"
type="material-community"
size={75}
color={colors.danger}
/>
<Text style={styles.noRecomText}>
Belum ada rekomendasi dari nutritionis
</Text>
</View>
);
} }
return ( return (
<ScrollView contentContainerStyle={layoutStyles}> <ScrollView contentContainerStyle={layoutStyles}>
......
Supports Markdown
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