Fakultas Ilmu Komputer UI

index.tsx 1.91 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import React, { FC } from 'react';
import { ScrollView } from 'react-native-gesture-handler';
import { BigButton, Loader } from 'components/core';
import { useNavigation } from '@react-navigation/core';
import { useApi, useDownloadFiles } from 'hooks';

import { ClientCardNutritionist } from 'scenes/nutritionist/ClientListNutritionist/components';
import { retrieveClientListApi } from 'services/profiles';
import * as ROUTES from 'constants/routes';

import { layoutStyles } from 'styles';
import { Dimensions, StyleSheet, View } from 'react-native';
import { Section } from 'components/layout';
import { getAbsoluteUrl } from 'utils/format';
15
import { UserRole } from 'services/auth/models';
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

const ClientListAdmin: FC = () => {
  const navigation = useNavigation();
  const { isLoading, data: clients = [] } = useApi(retrieveClientListApi);
  const { download } = useDownloadFiles(getAbsoluteUrl('exportcsv'));

  if (isLoading) {
    return <Loader />;
  }

  return (
    <View style={layoutStyles}>
      <ScrollView style={styles.container}>
        {clients.map((client, idx) => (
          <ClientCardNutritionist
            key={idx}
            clientName={client.user.name}
            onPressClientProfile={() => {
              navigation.navigate(ROUTES.clientProfileAdmin, {
                id: client.diet_questionnaire_id,
36
                role: UserRole.ADMIN,
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
              });
            }}
            onPressClientDietReport={() => {
              navigation.navigate(ROUTES.clientDietReportAdmin, {});
            }}
            onPressClientChat={() => {
              navigation.navigate(ROUTES.clientChatAdmin, {});
            }}
          />
        ))}
      </ScrollView>

      <Section>
        <BigButton title="Download CSV" onPress={download} />
      </Section>
    </View>
  );
};

const styles = StyleSheet.create({
  container: { height: Dimensions.get('window').height * 0.83 },
});

export default ClientListAdmin;