Skip to content

Commit

Permalink
Merge branch 'main' into 226-as-a-user-i-want-to-be-directed-to-the-m…
Browse files Browse the repository at this point in the history
…ain-page-after-logging-in
  • Loading branch information
k-allagbe committed Oct 4, 2024
2 parents 4f219d8 + be49e19 commit a1359ef
Show file tree
Hide file tree
Showing 8 changed files with 1,893 additions and 1,176 deletions.
6 changes: 4 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ version: '3.8'

services:
nginx:
image: ghcr.io/ai-cfia/nginx:0.0.2
image: ghcr.io/ai-cfia/nginx:0.0.4
container_name: fertiscan-frontend-nginx
restart: always
ports:
- "80:80"
environment:
- BACKEND_PORT=5000 # Needs to point to the internal port of the backend service (5000)
- FRONTEND_PORT=3000 # Needs to point to the internal port of the frontend service (3000)
- SWAGGER_PATH=swagger # Use anything but '/api' to avoid conflicts with the backend. Make sure to use the same value for API_BASE_PATH in the backend. e.g. 'API_BASE_PATH=/swagger'
depends_on:
- frontend
- backend
Expand Down Expand Up @@ -48,14 +49,15 @@ services:
- fertiscan-network

postgres:
image: ghcr.io/ai-cfia/postgres:0.0.4
image: ghcr.io/ai-cfia/postgres:0.0.5
container_name: fertiscan-frontend-postgres
restart: always
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=fertiscan
- BB_URL=${BB_URL}
- PROJECT_NAME=fertiscan
- BB_SERVICE_ACCOUNT=${BB_SERVICE_ACCOUNT}
- BB_SERVICE_KEY=${BB_SERVICE_KEY}
- INSTANCE_ID=${BB_INSTANCE_ID}
Expand Down
2,941 changes: 1,832 additions & 1,109 deletions package-lock.json

Large diffs are not rendered by default.

39 changes: 13 additions & 26 deletions src/Components/DragDropFileInput/DragDropFileInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,24 +189,8 @@ const DragDropFileInput: React.FC<FileInputProps> = ({
input.click();
};

// This function gets the camera permission status
const getCameraPermission = async () => {
try {
setHasPermission(
(await navigator.mediaDevices.getUserMedia({ video: true }))
? true
: false,
);
} catch (err) {
setHasPermission(false);
}
};

const selectCamera = async () => {
if (hasPermission === null) {
await getCameraPermission();
if (!hasPermission) return;
} else if (!hasPermission) {
if (!hasPermission) {
return;
}

Expand All @@ -225,19 +209,22 @@ const DragDropFileInput: React.FC<FileInputProps> = ({
event: React.MouseEvent<HTMLDivElement>,
) => {
event.preventDefault();
getCameraPermission();
if (!hasPermission) {
showAlert(t("cameraPermissionError"), "error");
return;

// Request camera permission only when toggling to camera mode
if (!toggleMode) {
try {
await navigator.mediaDevices.getUserMedia({ video: true });
setHasPermission(true);
} catch (err) {
setHasPermission(false);
showAlert(t("cameraPermissionError"), "error");
return;
}
}

setToggleMode((currentMode) => !currentMode);
};

// Check camera permissions when the component mounts
useEffect(() => {
getCameraPermission();
}, []);

useEffect(() => {
if (toggleMode && cameraSwitch.current) {
cameraSwitch.current.classList.add("active");
Expand Down
2 changes: 2 additions & 0 deletions src/Pages/FormPage/FormPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ const FormPage = () => {
arrayMerge: combineMerge,
});

console.log("setForm inspection", inspection);

setData(populateFromJSON(data, inspection));
updateData();
setState({
Expand Down
16 changes: 8 additions & 8 deletions src/Utils/FormCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@ export const FertiliserForm = () =>
new Input(t("density"), "product.metrics.density"),
new Input(t("volume"), "product.metrics.volume"),
new Input(t("npk"), "product.npk"),
new Input(t("warranty"), "product.warranty"),
new Input(t("cautions_en"), "cautions.en"),
new Input(t("cautions_fr"), "cautions.fr"),
new Input(t("instructions_en"), "instructions.en"),
new Input(t("instructions_fr"), "instructions.fr"),
new Input(t("micronutrients_en"), "micronutrients.en"),
new Input(t("micronutrients_fr"), "micronutrients.fr"),
new Input(t("ingredients_en"), "ingredients.en"),
new Input(t("ingredients_fr"), "ingredients.fr"),
new Input(t("specifications_en"), "specifications.en"),
new Input(t("specifications_fr"), "specifications.fr"),
new Input(t("firstAid_en"), "first_aid.en"),
new Input(t("firstAid_fr"), "first_aid.fr"),
new Input(t("guaranteedAnalysis"), "guaranteed_analysis"),
]),
new Section(t("guaranteedAnalysis"), "guaranteed_analysis_fr", [
new Input(t("title"), "guaranteed_analysis.title"),
new Input(t("guaranteedAnalysis_en"), "guaranteed_analysis.en"),
new Input(t("guaranteedAnalysis_fr"), "guaranteed_analysis.fr"),
]),
new Section(t("inspection_comment"), "inspection_comment", [
new Input(t("addComment"), "inspection_comment"),
]),
]);

Expand Down
49 changes: 20 additions & 29 deletions src/interfaces/Inspection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,6 @@ export interface ProductInformation {
k: number | null;
}

export interface Specification {
humidity: number | null;
ph: number | null;
solubility: number | null;
edited: boolean;
}

export interface LocalizedSpecifications {
en: Specification[];
fr: Specification[];
}

export interface OrganizationInformation {
id: string | null;
name: string | null;
Expand All @@ -57,6 +45,17 @@ export interface OrganizationInformation {
phone_number: string | null;
}

export interface Title {
en: string | null;
fr: string | null;
}

export interface GuaranteedAnalysis {
title: Title;
en: NamedValue[];
fr: NamedValue[];
}

export default interface Inspection {
inspection_id: string | null;
verified: boolean;
Expand All @@ -65,11 +64,9 @@ export default interface Inspection {
product: ProductInformation;
cautions: LocalizedSubLabel;
instructions: LocalizedSubLabel;
micronutrients: LocalizedValues;
ingredients: LocalizedValues;
specifications: LocalizedSpecifications;
first_aid: LocalizedSubLabel;
guaranteed_analysis: NamedValue[];
inspection_comment: string | null;
guaranteed_analysis: GuaranteedAnalysis;
}

export const createDefaultValue = (): Value => ({
Expand All @@ -85,11 +82,9 @@ export const createDefaultNamedValue = (): NamedValue => ({
edited: false,
});

export const createDefaultSpecification = (): Specification => ({
humidity: null,
ph: null,
solubility: null,
edited: false,
export const createDefaultTitle = (): Title => ({
en: null,
fr: null,
});

export const createDefaultInspection = (): Inspection => ({
Expand Down Expand Up @@ -127,18 +122,14 @@ export const createDefaultInspection = (): Inspection => ({
},
cautions: { en: [], fr: [] },
instructions: { en: [], fr: [] },
micronutrients: {
ingredients: {
en: [createDefaultNamedValue()],
fr: [createDefaultNamedValue()],
},
ingredients: {
guaranteed_analysis: {
title: createDefaultTitle(),
en: [createDefaultNamedValue()],
fr: [createDefaultNamedValue()],
},
specifications: {
en: [createDefaultSpecification()],
fr: [createDefaultSpecification()],
},
first_aid: { en: [], fr: [] },
guaranteed_analysis: [createDefaultNamedValue()],
inspection_comment: null,
});
8 changes: 7 additions & 1 deletion src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,11 @@
"logout": "Log Out",
"mustLogin": "You must be logged in to submit a label",
"loggedIn": "You are successfully logged in",
"registered": "You are successfully registered"
"registered": "You are successfully registered",
"inspection_comment": "Comment",
"guaranteedAnalysis_fr": "Guaranteed Analysis (French)",
"guaranteedAnalysis_en": "Guaranteed Analysis (English)",
"title":"Title",
"nutrients":"Nutrients",
"addComment": "Add a comment"
}
8 changes: 7 additions & 1 deletion src/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,11 @@
"logout": "Se déconnecter",
"mustLogin": "Vous devez être connecté pour enregistrer un label",
"loggedIn": "Vous êtes connecté",
"registered": "Vous êtes enregistré"
"registered": "Vous êtes enregistré",
"inspection_comment": "Commentaire",
"guaranteedAnalysis_fr": "Analyse garantie (français)",
"guaranteedAnalysis_en": "Analyse garantie (anglais)",
"title":"Titre",
"nutrients":"Nutriments",
"addComment": "Ajouter un commentaire"
}

0 comments on commit a1359ef

Please sign in to comment.