Skip to content

Commit 1646863

Browse files
authored
Merge pull request #42 from swiftss-org/staging
feat: integrate with api and add login API functionality
2 parents 69f8289 + 8460e23 commit 1646863

38 files changed

+710
-161
lines changed

.eslintrc.json

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
{
2-
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "prettier"],
3-
"plugins": ["react", "@typescript-eslint", "react-hooks"],
4-
2+
"extends": [
3+
"eslint:recommended",
4+
"plugin:@typescript-eslint/recommended",
5+
"prettier"
6+
],
7+
"plugins": [
8+
"react",
9+
"@typescript-eslint",
10+
"react-hooks",
11+
"import",
12+
"better-styled-components"
13+
],
514
"env": {
615
"node": true,
716
"browser": true,
@@ -10,11 +19,54 @@
1019
"es6": true
1120
},
1221
"rules": {
22+
"better-styled-components/sort-declarations-alphabetically": 2,
23+
"import/order": [
24+
"error",
25+
{
26+
"groups": [
27+
"builtin",
28+
"external",
29+
[
30+
"internal",
31+
"parent",
32+
"sibling",
33+
"index",
34+
"object"
35+
]
36+
],
37+
"pathGroups": [
38+
{
39+
"pattern": "react",
40+
"group": "external",
41+
"position": "before"
42+
},
43+
{
44+
"pattern": "src/**",
45+
"group": "internal"
46+
},
47+
{
48+
"pattern": "theme/**",
49+
"group": "internal"
50+
}
51+
],
52+
"pathGroupsExcludedImportTypes": [
53+
"react"
54+
],
55+
"alphabetize": {
56+
"order": "asc",
57+
"caseInsensitive": true
58+
},
59+
"newlines-between": "always"
60+
}
61+
],
1362
"@typescript-eslint/naming-convention": [
1463
"error",
1564
{
1665
"selector": "typeLike",
17-
"format": ["PascalCase", "UPPER_CASE"]
66+
"format": [
67+
"PascalCase",
68+
"UPPER_CASE"
69+
]
1870
}
1971
],
2072
"react-hooks/rules-of-hooks": "error",
@@ -23,6 +75,7 @@
2375
"no-unused-expressions": "off",
2476
"@typescript-eslint/no-unused-expressions": "error",
2577
"no-unused-vars": "off",
78+
"@typescript-eslint/explicit-module-boundary-types": 0,
2679
"@typescript-eslint/no-unused-vars": [
2780
"error",
2881
{

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"@emotion/jest": "^11.2.1",
1212
"@emotion/react": "^11.1.5",
1313
"@emotion/styled": "^10.0.27",
14-
"@orfium/ictinus": "^2.63.0",
14+
"@orfium/ictinus": "^2.70.2",
1515
"@testing-library/jest-dom": "^5.11.9",
1616
"@testing-library/react": "^11.2.5",
1717
"@testing-library/user-event": "^13.1.3",
@@ -30,6 +30,7 @@
3030
"react": "^17.0.2",
3131
"react-dom": "^17.0.2",
3232
"react-final-form": "^6.5.3",
33+
"react-final-form-listeners": "^1.0.3",
3334
"react-query": "^3.16.0",
3435
"react-router-dom": "^5.2.0",
3536
"react-scripts": "4.0.3",
@@ -73,6 +74,8 @@
7374
"babel-plugin-styled-components": "^1.12.0",
7475
"cross-env": "^7.0.3",
7576
"eslint-config-prettier": "^7.2.0",
77+
"eslint-plugin-better-styled-components": "^1.1.2",
78+
"eslint-plugin-import": "^2.23.4",
7679
"husky": "^6.0.0",
7780
"lint-staged": "^10.5.4",
7881
"prettier": "^2.2.1",

server.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/* eslint-disable @typescript-eslint/no-var-requires */
2-
const express = require('express');
32
const path = require('path');
4-
const serverPort = process.env.PORT || 3000;
3+
4+
const express = require('express');
5+
const serverPort = process.env.PORT || 3001;
56
const environment = process.env.NODE_ENV || 'development';
67

78
// construct a mini server

src/App.style.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@ import styled from '@emotion/styled';
33
import theme from 'theme/globals';
44

55
export const AppWrapper = styled.div`
6-
width: 100%;
7-
height: calc(100vh);
86
background-color: ${theme.defaultBackgroundColor};
9-
font-family: ${theme.fontFamily};
107
color: ${theme.defaultTextColor};
11-
position: relative;
8+
font-family: ${theme.fontFamily};
9+
height: calc(100vh);
1210
overflow: hidden;
11+
position: relative;
12+
width: 100%;
1313
`;
1414

1515
export const TopBar = styled.div`
16-
width: 100%;
17-
position: sticky;
18-
display: flex;
19-
flex-direction: row;
2016
align-items: center;
17+
border-bottom: 1px black solid;
2118
color: black;
19+
display: flex;
20+
flex-direction: row;
2221
font-weight: 700;
23-
border-bottom: 1px black solid;
22+
position: sticky;
23+
width: 100%;
2424
`;

src/App.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import React from 'react';
2-
import { BrowserRouter as Router } from 'react-router-dom';
2+
33
import { ThemeProvider } from '@orfium/ictinus';
44
import { QueryClient, QueryClientProvider } from 'react-query';
5+
import { BrowserRouter as Router } from 'react-router-dom';
56

6-
import theme from 'theme/globals';
77
import { AppWrapper } from './App.style';
88
import Routes from './routing/Routes';
9+
import theme from 'theme/globals';
910

10-
const queryClient = new QueryClient();
11+
const queryClient = new QueryClient({
12+
defaultOptions: { queries: { refetchOnWindowFocus: false, refetchOnReconnect: false } },
13+
});
1114

1215
const App: React.FC = () => {
1316
return (

src/api/patientsAPI/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import patientsAPI from './patientsAPI';
2+
3+
export default {
4+
single: patientsAPI,
5+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
2+
import { RegisterPatientPayload } from '../../models/apiTypes';
3+
import { METHODS, request } from '../axiosInstances';
4+
5+
export default {
6+
getHospitals: () => request(METHODS.GET, '/hospitals/', {}),
7+
registerPatient: (params: RegisterPatientPayload) =>
8+
request(METHODS.POST, '/patients/', { params }),
9+
};

src/api/userAPI/userAPI.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
2+
import { LoginResponse } from '../../models/apiTypes';
23
import { METHODS, request } from '../axiosInstances';
3-
import { SignInParams } from '../../models/apiTypes';
44

55
export default {
6-
signIn: (params: SignInParams) => request(METHODS.POST, '/sign-in/', { params }),
6+
signIn: (params: LoginResponse) => request(METHODS.POST, '/sign-in/', { params }),
77
};

src/common.style.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import { css } from '@emotion/react';
12
import styled from '@emotion/styled';
23
import { grid } from '@orfium/ictinus/dist/theme/functions';
4+
35
import { flex } from './theme/functions';
4-
import { css } from '@emotion/react';
56

67
export const PageWrapper = styled.div`
78
${flex};
@@ -44,26 +45,26 @@ export const CheckBoxContainer = styled.div<{ error?: boolean; checked?: boolean
4445

4546
export const FieldsContainer = styled.div<{ withMargin?: boolean }>`
4647
${grid};
47-
grid-template-columns: 1fr 1fr;
4848
column-gap: 38px;
49-
row-gap: 24px;
49+
grid-template-columns: 1fr 1fr;
5050
margin-bottom: ${(props) => (props.withMargin ? '24px' : null)};
51+
row-gap: 24px;
5152
`;
5253

5354
export const LongFieldWrapper = styled.div`
5455
grid-column: 1 / 3;
5556
`;
5657

5758
export const FieldWrapper = styled.div`
58-
width: 100%;
5959
box-sizing: border-box;
60+
width: 100%;
6061
`;
6162

6263
export const RadioText = styled.span`
63-
min-height: 48px;
64-
display: inline-flex;
6564
align-items: center;
65+
display: inline-flex;
6666
margin-left: 8px;
67+
min-height: 48px;
6768
`;
6869

6970
// eslint-disable-next-line @typescript-eslint/ban-ts-comment

src/hooks/api/patientHooks.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { AxiosError } from 'axios';
2+
import { ReactQueryKeys } from 'hooks/constants';
3+
import { useMutation, useQuery } from 'react-query';
4+
import { useHistory } from 'react-router-dom';
5+
6+
import patientsAPI from '../../api/patientsAPI';
7+
import { HospitalsResponse, RegisterPatientPayload } from '../../models/apiTypes';
8+
import { RegisterPatientFormType } from '../../pages/RegisterPatient/types';
9+
import urls from '../../routing/urls';
10+
11+
export const useGetHospitals = () => {
12+
return useQuery<HospitalsResponse, AxiosError, HospitalsResponse>(
13+
ReactQueryKeys.HospitalsQuery,
14+
async () => {
15+
const { request } = patientsAPI.single.getHospitals();
16+
const data = await request();
17+
18+
return data;
19+
},
20+
{
21+
onError: (errors) => {
22+
console.log(errors);
23+
},
24+
25+
retry: false,
26+
}
27+
);
28+
};
29+
30+
export const useRegisterPatient = () => {
31+
const history = useHistory();
32+
33+
return useMutation<RegisterPatientPayload, AxiosError, RegisterPatientFormType>(
34+
(params) => {
35+
const { request } = patientsAPI.single.registerPatient({
36+
full_name: params.name,
37+
address: params.address,
38+
age: params.age,
39+
year_of_birth: params.yearOfBirth,
40+
phone_1: params.phone1,
41+
phone_2: params.phone2,
42+
hospital_id: params.center.value,
43+
national_id: params.nationalId,
44+
gender: params.gender,
45+
});
46+
return request();
47+
},
48+
{
49+
onSuccess: () => {
50+
history.replace(urls.patients());
51+
},
52+
onError: (errors) => {
53+
console.log(errors);
54+
},
55+
}
56+
);
57+
};

0 commit comments

Comments
 (0)