Skip to content

Commit

Permalink
rdsur flow on self wells
Browse files Browse the repository at this point in the history
  • Loading branch information
JavaRip committed Sep 15, 2024
1 parent 5dfdb88 commit 54c2d53
Show file tree
Hide file tree
Showing 15 changed files with 295 additions and 157 deletions.
2 changes: 1 addition & 1 deletion app/client/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = {
'plugin:@typescript-eslint/recommended',
'plugin:react-hooks/recommended',
],
ignorePatterns: ['dist', '.eslintrc.cjs'],
ignorePatterns: ['dist', '.eslintrc.cjs', 'node_modules'],
parser: '@typescript-eslint/parser',
plugins: ['react-refresh'],
rules: {
Expand Down
2 changes: 1 addition & 1 deletion app/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0 --fix",
"preview": "vite preview"
},
"dependencies": {
Expand Down
14 changes: 7 additions & 7 deletions app/client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,20 @@ function App() {
marginBottom='2rem'
alignItems='center'
>
<Route path='/:id/depth' component={Depth} />
<Route path='/:id/flooding' component={Flooding} />
<Route path='/:id/forgot-password' component={ForgotPassword} />
<Route path='/:id/region' component={Region} />
<Route path='/:id/result' component={Result} />
<Route path='/:id/review' component={Review} />
<Route path='/:id/staining' component={Staining} />
<Route path='/briefing' component={Briefing} />
<Route path='/depth' component={Depth} />
<Route path='/flooding' component={Flooding} />
<Route path='/forgot-password' component={ForgotPassword} />
<Route path='/landing' component={Landing} />
<Route path='/login' component={Login} />
<Route path='/my-wells' component={MyWells} />
<Route path='/privacy-policy' component={PrivacyPolicy} />
<Route path='/:id/region' component={Region} />
<Route path='/:id/result' component={Result} />
<Route path='/:id/review' component={Review} />
<Route path='/sign-up' component={SignUp} />
<Route path='/staining-guide' component={StainingGuide} />
<Route path='/:id/staining' component={Staining} />
<Route path='/well/:id' component={Well} />
</Stack>
</Route>
Expand Down
53 changes: 50 additions & 3 deletions app/client/src/pages/Depth/Depth.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import { Box, Button, Card, Slider, Switch, TextField, Typography } from "@mui/material";
import config from "../../config";
import { navigate } from "wouter/use-browser-location";
import { useState } from "react";
import { useEffect, useState } from "react";
import PredictorsStorage from "../../utils/PredictorsStorage";
import { IAccessToken } from "../../../types";
import { useRoute } from "wouter";
import AccessToken from "../../utils/AccessToken";

export default function Depth(): JSX.Element {
const [, params] = useRoute('/:id/depth');
const wellId = params?.id;
const [token, setToken] = useState<IAccessToken>();

const [unit, setUnit] = useState<'m' | 'ft'>('ft');
const [depth, setDepth] = useState(0);

Expand All @@ -24,6 +31,21 @@ export default function Depth(): JSX.Element {
if (unit === 'm') setDepth(Math.floor(depth / 0.3048));
}

useEffect(() => {
async function fetchToken() {
const token = await AccessToken.get();

if (token == null) {
navigate(`${config.basePath}/login`);
return;
}

setToken(token);
}

fetchToken();
}, []);

return (
<>
<Typography marginBottom='1rem' textAlign='center' variant='h4'>
Expand Down Expand Up @@ -99,15 +121,40 @@ export default function Depth(): JSX.Element {
<Button
sx={{ width: '90%', height: '4rem' }}
variant='contained'
onClick={() => {
onClick={async () => {
PredictorsStorage.set({
depth: {
unit,
value: depth
}
});
const headers: HeadersInit = {};
if (token) {
headers['authorization'] = `Bearer ${token.id}`;
}

const depthMeters = (() => {
if (unit === 'm') return depth;
return depth * 0.3048;
})();

const body = { depth: depthMeters };

const res = await fetch(`${config.basePath}/api/v1/self/well/${wellId}`, {
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
...headers,
},
body: JSON.stringify(body),
});

if (!res.ok) {
console.error('Failed to update well:', res);
return;
}

navigate(`${config.basePath}/flooding`);
navigate(`${config.basePath}/${wellId}/flooding`);
}}
>
Review Input
Expand Down
55 changes: 51 additions & 4 deletions app/client/src/pages/Flooding/Flooding.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import { Button, Card, FormControl, FormControlLabel, Radio, RadioGroup, Stack, Typography } from "@mui/material";
import config from "../../config";
import { navigate } from "wouter/use-browser-location";
import { useState } from "react";
import { useEffect, useState } from "react";
import PredictorsStorage from "../../utils/PredictorsStorage";
import { useRoute } from "wouter";
import { IAccessToken } from "../../../types";
import AccessToken from "../../utils/AccessToken";

export default function Depth(): JSX.Element {
const [, params] = useRoute('/:id/flooding');
const wellId = params?.id;
const [token, setToken] = useState<IAccessToken>();
console.log('================================');
console.log(wellId);

const [flooding, setFlooding] = useState<'yes' | 'no'>();
const [error, setError] = useState<boolean>(false);

Expand All @@ -13,6 +22,21 @@ export default function Depth(): JSX.Element {
setError(false);
}

useEffect(() => {
async function fetchToken() {
const token = await AccessToken.get();

if (token == null) {
navigate(`${config.basePath}/login`);
return;
}

setToken(token);
}

fetchToken();
}, []);

return (
<>
<Typography marginBottom='1rem' textAlign='center' variant='h4'>
Expand Down Expand Up @@ -65,7 +89,7 @@ export default function Depth(): JSX.Element {
<Button
sx={{ width: '90%', height: '4rem' }}
variant='contained'
onClick={() => {
onClick={async () => {
if (!flooding) {
setError(true);
return;
Expand All @@ -77,10 +101,33 @@ export default function Depth(): JSX.Element {
flooding: floodingBool,
});

navigate(`${config.basePath}/review`);
const body = { flooding: floodingBool };

const headers: HeadersInit = {};

if (token) {
headers['authorization'] = `Bearer ${token.id}`;
}

const res = await fetch(`${config.basePath}/api/v1/self/well/${wellId}`, {
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
...headers,
},
body: JSON.stringify(body),
});

if (!res.ok) {
console.error('Failed to update well:', res);
return;
}
console.log('submitted flooding', JSON.stringify(body));

navigate(`${config.basePath}/${wellId}/review`);
}}
>
Review Input
Next Step
</Button>
</>
);
Expand Down
12 changes: 6 additions & 6 deletions app/client/src/pages/MyWells/MyWells.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default function MyWells(): JSX.Element {
headers: {
authorization: `Bearer ${token.id}`,
}
})
});

if (!result.ok) {
console.error('Failed to fetch wells:', result);
Expand All @@ -39,8 +39,8 @@ export default function MyWells(): JSX.Element {
flooding: well.flooding,
staining: well.staining,
prediction: well.prediction,
}
}))
};
}));
}

async function addWell() {
Expand All @@ -56,7 +56,7 @@ export default function MyWells(): JSX.Element {
headers: {
authorization: `Bearer ${token.id}`,
}
})
});

if (!result.ok) {
console.error('Failed to add well:', result);
Expand All @@ -68,7 +68,7 @@ export default function MyWells(): JSX.Element {

useEffect(() => {
fetchUserWells();
}, [])
}, []);

return (
<>
Expand Down Expand Up @@ -96,4 +96,4 @@ export default function MyWells(): JSX.Element {
</Box>
</>
);
};
}
2 changes: 1 addition & 1 deletion app/client/src/pages/MyWells/WellCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface props {
}

export default function WellCard({ well }: props): JSX.Element {
console.log(well)
console.log(well);
return (
<Card
variant="outlined"
Expand Down
10 changes: 3 additions & 7 deletions app/client/src/pages/Region/Region.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export type RegionErrors = {
};

export default function Region(): JSX.Element {
const [match, params] = useRoute('/:id/region');
const [, params] = useRoute('/:id/region');
const wellId = params?.id;
const [token, setToken] = useState<IAccessToken>();

Expand Down Expand Up @@ -81,10 +81,6 @@ export default function Region(): JSX.Element {
fetchToken();
}, []);

if (!match) {
return <div>Well not found</div>;
}

if (!regionTranslations) {
return (
<Stack direction='column' alignContent='center' justifyContent='center'>
Expand Down Expand Up @@ -171,7 +167,7 @@ export default function Region(): JSX.Element {
union: selectedUnion.union,
mouza: selectedMouza,
}
}
};

if (regionGeovalidated) {
body.geolocation = geolocation;
Expand All @@ -186,7 +182,7 @@ export default function Region(): JSX.Element {
body: JSON.stringify({
...body
})
})
});

if (!res.ok) {
console.error('Failed to update well:', res);
Expand Down
6 changes: 3 additions & 3 deletions app/client/src/pages/Result/produceEstimate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default function produceEstimate(
exist in the prediction data for this region
*/
if (regionStrataKey === 's15' && 'm2' in regionStrataModel) {
if (predictors.wellStaining === 'Black' && regionStrataModel.m2 !== undefined) {
if (predictors.wellStaining === 'black' && regionStrataModel.m2 !== undefined) {
return regionStrataModel.m2;
} else if (predictors.flooding && regionStrataModel.m9 !== undefined) {
return regionStrataModel.m9;
Expand All @@ -46,9 +46,9 @@ export default function produceEstimate(
throw new Error('model keys required for flooding model misisng');
}
} else {
if (predictors.wellStaining === 'Black' || predictors.utensilStaining === 'Black') {
if (predictors.wellStaining === 'black' || predictors.utensilStaining === 'black') {
return 1;
} else if (predictors.wellStaining === 'Red' || predictors.utensilStaining === 'Red') {
} else if (predictors.wellStaining === 'red' || predictors.utensilStaining === 'red') {
if (regionStrataModel.m !== undefined) {
return regionStrataModel.m;
} else {
Expand Down
6 changes: 3 additions & 3 deletions app/client/src/pages/SignUp/SignUp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default function SignUp(): JSX.Element {
async function handleSubmit() {
if (!name || !email || !password || !confirmPassword) {
setError('All fields are required');
return
return;
}

const passwordError = validatePassword(password);
Expand All @@ -64,13 +64,13 @@ export default function SignUp(): JSX.Element {
'Content-Type': 'application/json',
},
body: JSON.stringify({ name, email, password }),
})
});

const resBody = await result.json();

if (!result.ok) {
if (resBody.knownError === true) {
const knownError: KnownServerError = resBody
const knownError: KnownServerError = resBody;

if (knownError.name === 'ValidationError') {
setError(knownError.message);
Expand Down
Loading

0 comments on commit 54c2d53

Please sign in to comment.