Fakultas Ilmu Komputer UI

Commit cf0dff24 authored by Kefas Satrio Bangkit Solideantyo's avatar Kefas Satrio Bangkit Solideantyo
Browse files

[REFACTOR] rename diet profile for admin to ClientDietRecommendationForAdmin,...

[REFACTOR] rename diet profile for admin to ClientDietRecommendationForAdmin, change diet profile page for admin
parent e2bcf02b
Pipeline #79063 passed with stages
in 26 minutes and 49 seconds
...@@ -27,7 +27,7 @@ import { ...@@ -27,7 +27,7 @@ import {
ClientListNutritionist, ClientListNutritionist,
ComingSoonPage, ComingSoonPage,
ClientProfile, ClientProfile,
ClientProfileForAdmin, ClientDietRecommendationForAdmin,
PaymentWebView, PaymentWebView,
ProfileDietRecommendation, ProfileDietRecommendation,
ClientListAdmin, ClientListAdmin,
...@@ -190,7 +190,7 @@ export const adminNavigation: NavRoute[] = [ ...@@ -190,7 +190,7 @@ export const adminNavigation: NavRoute[] = [
}, },
{ {
name: ROUTES.clientProfileAdmin, name: ROUTES.clientProfileAdmin,
component: ClientProfileForAdmin, component: ReadOnlyDietProfile,
header: 'Profil Klien', header: 'Profil Klien',
}, },
{ {
...@@ -203,6 +203,11 @@ export const adminNavigation: NavRoute[] = [ ...@@ -203,6 +203,11 @@ export const adminNavigation: NavRoute[] = [
component: ComingSoonPage, component: ComingSoonPage,
header: 'Profil Klien', header: 'Profil Klien',
}, },
{
name: ROUTES.clientDietRecommendation,
component: ClientDietRecommendationForAdmin,
header: 'Rekomendasi Profil Diet',
},
]; ];
export const testNavigation: NavRoute[] = [ export const testNavigation: NavRoute[] = [
......
...@@ -38,3 +38,4 @@ export const clientListForAdmin = `${admin}/client-list`; ...@@ -38,3 +38,4 @@ export const clientListForAdmin = `${admin}/client-list`;
export const clientProfileAdmin = `${admin}/client-profile`; export const clientProfileAdmin = `${admin}/client-profile`;
export const clientDietReportAdmin = `${admin}/client-diet-report`; export const clientDietReportAdmin = `${admin}/client-diet-report`;
export const clientChatAdmin = `${admin}/client-chat`; export const clientChatAdmin = `${admin}/client-chat`;
export const clientDietRecommendation = `${admin}/client-diet-recommendation`;
...@@ -12,14 +12,13 @@ import { layoutStyles } from 'styles'; ...@@ -12,14 +12,13 @@ import { layoutStyles } from 'styles';
import { Dimensions, StyleSheet, View } from 'react-native'; import { Dimensions, StyleSheet, View } from 'react-native';
import { Section } from 'components/layout'; import { Section } from 'components/layout';
import { getAbsoluteUrl } from 'utils/format'; import { getAbsoluteUrl } from 'utils/format';
import { UserRole } from 'services/auth/models';
const ClientListAdmin: FC = () => { const ClientListAdmin: FC = () => {
const navigation = useNavigation(); const navigation = useNavigation();
const { isLoading, data: clients = [] } = useApi(retrieveClientListApi); const { isLoading, data: clients = [] } = useApi(retrieveClientListApi);
const { download } = useDownloadFiles(getAbsoluteUrl('exportcsv')); const { download } = useDownloadFiles(getAbsoluteUrl('exportcsv'));
console.log(clients);
if (isLoading) { if (isLoading) {
return <Loader />; return <Loader />;
} }
...@@ -34,6 +33,7 @@ const ClientListAdmin: FC = () => { ...@@ -34,6 +33,7 @@ const ClientListAdmin: FC = () => {
onPressClientProfile={() => { onPressClientProfile={() => {
navigation.navigate(ROUTES.clientProfileAdmin, { navigation.navigate(ROUTES.clientProfileAdmin, {
id: client.diet_questionnaire_id, id: client.diet_questionnaire_id,
role: UserRole.ADMIN,
}); });
}} }}
onPressClientDietReport={() => { onPressClientDietReport={() => {
......
...@@ -26,4 +26,4 @@ export { default as ClientListNutritionist } from './nutritionist/ClientListNutr ...@@ -26,4 +26,4 @@ export { default as ClientListNutritionist } from './nutritionist/ClientListNutr
export { default as ClientListAdmin } from './admin/ClientListAdmin'; export { default as ClientListAdmin } from './admin/ClientListAdmin';
export { default as ClientProfile } from './profile/ClientProfile'; export { default as ClientProfile } from './profile/ClientProfile';
export { default as ClientProfileForAdmin } from './profile/ClientProfileForAdmin'; export { default as ClientDietRecommendationForAdmin } from './profile/ClientDietRecommendationForAdmin';
...@@ -7,6 +7,7 @@ import * as ROUTES from 'constants/routes'; ...@@ -7,6 +7,7 @@ import * as ROUTES from 'constants/routes';
import { retrieveClientListApi } from 'services/profiles'; import { retrieveClientListApi } from 'services/profiles';
import { useApi } from 'hooks'; import { useApi } from 'hooks';
import { Loader, EmptyDataPage } from 'components/core'; import { Loader, EmptyDataPage } from 'components/core';
import { UserRole } from 'services/auth/models';
const ClientListNutritionist: FC = () => { const ClientListNutritionist: FC = () => {
const navigation = useNavigation(); const navigation = useNavigation();
...@@ -27,6 +28,7 @@ const ClientListNutritionist: FC = () => { ...@@ -27,6 +28,7 @@ const ClientListNutritionist: FC = () => {
onPressClientProfile={() => { onPressClientProfile={() => {
navigation.navigate(ROUTES.clientProfileNutritionist, { navigation.navigate(ROUTES.clientProfileNutritionist, {
id: client.diet_questionnaire_id, id: client.diet_questionnaire_id,
role: UserRole.NUTRITIONIST,
}); });
}} }}
onPressClientDietReport={() => { onPressClientDietReport={() => {
......
...@@ -2,7 +2,7 @@ import React from 'react'; ...@@ -2,7 +2,7 @@ import React from 'react';
import { render, waitFor } from '@testing-library/react-native'; import { render, waitFor } from '@testing-library/react-native';
import axios from 'axios'; import axios from 'axios';
import ClientProfileForAdmin from '.'; import ClientDietRecommendationForAdmin from '.';
import { mockDietRecommendation } from '__mocks__/dietRecommendation'; import { mockDietRecommendation } from '__mocks__/dietRecommendation';
jest.mock('axios'); jest.mock('axios');
...@@ -18,7 +18,7 @@ jest.mock('@react-navigation/native', () => { ...@@ -18,7 +18,7 @@ jest.mock('@react-navigation/native', () => {
}; };
}); });
describe('ClientProfileForAdmin', () => { describe('ClientDietRecommendationForAdmin', () => {
const retrievedietRecommendationByIdApi = () => const retrievedietRecommendationByIdApi = () =>
Promise.resolve({ Promise.resolve({
status: 200, status: 200,
...@@ -27,7 +27,7 @@ describe('ClientProfileForAdmin', () => { ...@@ -27,7 +27,7 @@ describe('ClientProfileForAdmin', () => {
it('fetches data from backend and renders correctly', async () => { it('fetches data from backend and renders correctly', async () => {
mockAxios.request.mockImplementationOnce(retrievedietRecommendationByIdApi); mockAxios.request.mockImplementationOnce(retrievedietRecommendationByIdApi);
render(<ClientProfileForAdmin />); render(<ClientDietRecommendationForAdmin />);
await waitFor(() => expect(mockAxios.request).toBeCalled()); await waitFor(() => expect(mockAxios.request).toBeCalled());
}); });
}); });
...@@ -7,7 +7,7 @@ import { useApi } from 'hooks'; ...@@ -7,7 +7,7 @@ import { useApi } from 'hooks';
import { retrieveDietRecommendationByIdApi } from 'services/dietRecommendation'; import { retrieveDietRecommendationByIdApi } from 'services/dietRecommendation';
import { DietRecommendationResponse } from 'services/dietRecommendation/models'; import { DietRecommendationResponse } from 'services/dietRecommendation/models';
const ClientProfileForAdmin: FC = () => { const ClientDietRecommendationForAdmin: FC = () => {
const route = useRoute(); const route = useRoute();
const { id } = route.params as DietRecommendationResponse; const { id } = route.params as DietRecommendationResponse;
...@@ -21,4 +21,4 @@ const ClientProfileForAdmin: FC = () => { ...@@ -21,4 +21,4 @@ const ClientProfileForAdmin: FC = () => {
return <ReadOnlyDietRecommendation data={data} />; return <ReadOnlyDietRecommendation data={data} />;
}; };
export default ClientProfileForAdmin; export default ClientDietRecommendationForAdmin;
...@@ -3,14 +3,20 @@ import { render } from 'utils/testing'; ...@@ -3,14 +3,20 @@ import { render } from 'utils/testing';
import * as ROUTES from 'constants/routes'; import * as ROUTES from 'constants/routes';
import ReadOnlyDietProfile from '.'; import ReadOnlyDietProfile from '.';
import { mockDietQuestionnaire } from '__mocks__/dietQuestionnaire'; import { UserRole } from 'services/auth/models';
jest.useFakeTimers(); jest.useFakeTimers();
describe('ReadOnlyDietProfile', () => { describe('ReadOnlyDietProfile', () => {
it('renders correctly', () => { it('renders correctly when role is nutritionist', () => {
render(<ReadOnlyDietProfile />, ROUTES.clientProfileNutritionist, { render(<ReadOnlyDietProfile />, ROUTES.clientProfileNutritionist, {
routeParams: mockDietQuestionnaire, routeParams: { id: 1, role: UserRole.NUTRITIONIST },
});
});
it('renders correctly when role is admin', () => {
render(<ReadOnlyDietProfile />, ROUTES.clientProfileNutritionist, {
routeParams: { id: 1, role: UserRole.ADMIN },
}); });
}); });
...@@ -19,7 +25,7 @@ describe('ReadOnlyDietProfile', () => { ...@@ -19,7 +25,7 @@ describe('ReadOnlyDietProfile', () => {
<ReadOnlyDietProfile />, <ReadOnlyDietProfile />,
ROUTES.clientProfileNutritionist, ROUTES.clientProfileNutritionist,
{ {
routeParams: { id: null }, routeParams: { id: null, role: UserRole.NUTRITIONIST },
}, },
); );
expect(getByText(/Klien belum mengisi diet questionnaire/i)).toBeTruthy(); expect(getByText(/Klien belum mengisi diet questionnaire/i)).toBeTruthy();
......
...@@ -17,16 +17,18 @@ import { useApi } from 'hooks'; ...@@ -17,16 +17,18 @@ 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 * as ROUTES from 'constants/routes'; import * as ROUTES from 'constants/routes';
import { UserRole } from 'services/auth/models';
interface QuestionnaireID { interface ParamsDietProfile {
id: number; id: number;
role: string;
} }
const ReadOnlyDietProfile: FC = () => { const ReadOnlyDietProfile: FC = () => {
const navigation = useNavigation(); const navigation = useNavigation();
const [activeSlide, setActiveSlide] = useState(0); const [activeSlide, setActiveSlide] = useState(0);
const route = useRoute(); const route = useRoute();
const { id } = route.params as QuestionnaireID; const { id, role } = route.params as ParamsDietProfile;
const { isLoading, data } = useApi(() => const { isLoading, data } = useApi(() =>
retrieveDietQuestionnaireByIdApi(id), retrieveDietQuestionnaireByIdApi(id),
); );
...@@ -56,15 +58,27 @@ const ReadOnlyDietProfile: FC = () => { ...@@ -56,15 +58,27 @@ const ReadOnlyDietProfile: FC = () => {
onSnapToItem={setActiveSlide} onSnapToItem={setActiveSlide}
/> />
<CarouselPagination index={activeSlide} length={5} /> <CarouselPagination index={activeSlide} length={5} />
<BigButton {role === UserRole.NUTRITIONIST ? (
title="Berikan Rekomendasi" <BigButton
onPress={() => title="Berikan Rekomendasi"
navigation.navigate(ROUTES.profileDietRecommendation, { onPress={() =>
name: dataDQR.user.name, navigation.navigate(ROUTES.profileDietRecommendation, {
id: id, name: dataDQR.user.name,
}) id: id,
} })
/> }
/>
) : (
<BigButton
title="Lihat Rekomendasi"
onPress={() =>
navigation.navigate(ROUTES.clientDietRecommendation, {
name: dataDQR.user.name,
id: id,
})
}
/>
)}
</ScrollView> </ScrollView>
); );
}; };
......
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