Fakultas Ilmu Komputer UI

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

Merge branch 'read-only-diet-profile-for-admin' into 'staging'

Change Client's Diet Profile For Admin

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