Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

397 as a dev I want to have a dev menu for demo purposes #399

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

SamuelPelletierEvraire
Copy link
Contributor

@SamuelPelletierEvraire SamuelPelletierEvraire commented Jan 6, 2025

DevMenu
Feature:

  1. Confirm all and unconfirm all button accessible on formPage.
  2. LoadData accessible on the HomePage to make the data load on the form page. (Organisation data don't load because the json file don't have the good form)
  3. Download json file (Working whit backend only) (Only available on formPage)
  4. Test alertBanner message (All message should be avalaible) (Available on all page)

To active the devMenu you need to create a use call "demoFertiscan" and log with it.

add devstore
add fill field with data
add dev menu
add dev menu when user demo is selected in login modal
move labelData.json to the root of the public folder
make the button appear only on the good page
remove demomessage from layout.tsx
Need to fix for labelDataValidator
remove console.log
Fix test
@SamuelPelletierEvraire SamuelPelletierEvraire force-pushed the 397-as-a-dev-i-want-to-have-a-dev-menu-for-demo-purposes branch from 5326863 to b72d8a8 Compare January 7, 2025 14:43
Copy link
Contributor

@ChromaticPanic ChromaticPanic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you need to run the code formatter for the files

@@ -10,86 +10,103 @@ import axios from "axios";
import Cookies from "js-cookie";
import { useRouter } from "next/navigation";
import { useEffect, useState } from "react";
import useDevStore from "@/stores/devStore";

function LabelDataValidationPage() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might as well update this to arrow function syntax
const LabelDataValidationPage = () =>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

src/app/page.tsx Outdated
@@ -11,6 +12,7 @@ import { useTranslation } from "react-i18next";
function HomePage() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use arrow function syntax
const HomePage = () =>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 48 to 52
if (
key === "errors" &&
typeof obj[key] === "object" &&
obj[key] !== null
) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

null check should probably go before the type check

also better to use != null instead of !== null because != null will work with both null and undefined

 if (
        key === "errors" &&
        obj[key] != null &&
        typeof obj[key] === "object" 
      ) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 57 to 59
}
} else if (typeof obj[key] === "object" && obj[key] !== null) {
const nestedErrors = extractErrorKeys(obj[key] as Record<string, unknown>, currentKey);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

} else if (obj[key] != null && typeof obj[key] === "object") {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Member

@k-allagbe k-allagbe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall we should avoid coupling the dev menu code with the real code to avoid breaking stuff. That would also ease developing both independently.

On that premise,

  • instead of coupling the visibility of the dev menu with the login / sign up process, we could try tying it to the cookie
  • instead of embedding the label data loading into the existing code, we could try creating dev mode twins for the relevant api routes
  • there probably should be an option to change the backend url

};
fetchData();
// eslint-disable-next-line react-hooks/exhaustive-deps
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's try to avoid disabling lints as much as possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'm agree but those are needed to avoid adding other const to the use effect that cause error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is for avoiding a warning.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

});
login(username, password).then((message) => {
if (message === "" && username === "demoFertiscan"){
useDevStore.getState().setIsDemoUser(true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tested that this is working as expected?

setErrorMessage(message);
});
login(username, password).then((message) => {
if (message === "" && username === "demoFertiscan"){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about sign up? Because our sign up process logs in the user automatically.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

useDevStore.getState().setIsDemoUser(true);
console.log("Dev mod enabled");
}else{
console.log(message);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tested that when we log out and log a user other than demoFertiscan in an environment other than development during the same session, the dev menu doesn't show?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

});
setLabelData({ ...labelData });
},
// eslint-disable-next-line react-hooks/exhaustive-deps
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's try to avoid disabling lints as much as possible. There must be a workaround to achieve what you want.

setErrorMessage(message);
});
login(username, password).then((message) => {
if (message === "" && username === "demoFertiscan"){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of a checking a single user, we could check a prefix like demo_. That would give us more options. Moreover, consider using an env var to avoid hardcoding.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No the point of this is that the use can use it when showing the app during reunions. But yes the env can be a good idea to add.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

As a dev, I want to have a dev menu for demo purposes.
3 participants