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

feat(levelPopup): Version 1 terminée #25

Merged
merged 11 commits into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import './globals.css';

import {Kodchasan, Nunito} from 'next/font/google';

import './globals.css';

import {LevelChoiceProvider} from '../src/context/LevelChoiceContext';
import Head from './Head';

const kodchasan = Kodchasan({
Expand All @@ -20,7 +21,9 @@ export default function RootLayout({children}: {children: React.ReactNode}) {
return (
<html lang="fr" className={`${kodchasan.variable} ${nunito.variable}`}>
<Head />
<body>{children}</body>
<body>
<LevelChoiceProvider>{children}</LevelChoiceProvider>
</body>
</html>
);
}
10 changes: 10 additions & 0 deletions app/levelSelection/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import LevelChoice from '../../src/components/LevelChoice/levelChoice';

export default function DisplayPopup() {
return (
<div>
<h1>Choisi ton niveaux de connaissance et tes objectif de voyage !</h1>
<LevelChoice />
</div>
);
}
8 changes: 4 additions & 4 deletions src/components/Form/Inputs/InputManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {Textarea} from './InputTextArea';

type InputType = 'text' | 'email' | 'textarea';

export interface InputsProps {
export type InputsProps = {
label: string;
name: string;
placeholder?: string;
Expand All @@ -13,9 +13,9 @@ export interface InputsProps {
onChange: (
event: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>,
) => void;
}
};

interface InputManagerProps {
type InputManagerProps = {
type: InputType;
label: string;
name: string;
Expand All @@ -25,7 +25,7 @@ interface InputManagerProps {
onChange: (
event: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>,
) => void;
}
};

export const Input: React.FC<InputManagerProps> = ({
label,
Expand Down
30 changes: 30 additions & 0 deletions src/components/Form/Inputs/InputRadio.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from 'react';

type InputRadioType = {
label: string;
name: string;
value: string;
handleChange: React.ChangeEventHandler<HTMLInputElement>;
defaultValue?: string;
};

export const InputRadio: React.FC<InputRadioType> = ({
label,
name,
value,
handleChange,
defaultValue,
}) => {
return (
<label>
<input
type="radio"
name={name}
value={value}
onChange={handleChange}
checked={defaultValue === value}
/>
{label}
</label>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.button {
background-color: #4caf50; /* Green */
border: none;
color: white;
padding: 10px 20px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
}
17 changes: 17 additions & 0 deletions src/components/LevelChoice/LevelButton/LevelChoiceButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';

import styles from './LevelChoiceButton.module.css';

type LevelChoiceButtonProps = {
onClick: () => void;
};

const LevelChoiceButton: React.FC<LevelChoiceButtonProps> = ({onClick}) => {
return (
<button className={styles.button} onClick={onClick}>
Choisissez votre niveau
</button>
);
};

export default LevelChoiceButton;
31 changes: 31 additions & 0 deletions src/components/LevelChoice/LevelPopup/LevelPopup.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
.popup {
position: fixed;
z-index: 100;
top: 0;
right: 0;
width: max-content;
padding: 20px;
background: white;
border: 2px solid rgba(128, 128, 128, 0.1);
border-radius: 15px;

.closeButton {
display: block;
margin-left: auto;
}

form {
div {
label {
display: inline-block;
padding: 10px 20px;
}
}

input[type='submit'] {
display: block;
width: 100%;
font-size: medium;
}
}
}
65 changes: 65 additions & 0 deletions src/components/LevelChoice/LevelPopup/LevelPopup.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import React, {useState} from 'react';

import {Goal, Level, useLevelChoice} from '../../../context/LevelChoiceContext';
import {InputRadio} from '../../Form/Inputs/InputRadio';
import styles from './LevelPopup.module.css';

const LEVELS: Level[] = ['Débutant', 'Intermédiaire', 'Avancé'];
const GOALS: Goal[] = ['Tourisme', 'Long-séjour', 'Expatrié'];

type LevelChoicePopupProps = {
handleClose: () => void;
};

const LevelChoicePopup: React.FC<LevelChoicePopupProps> = ({handleClose}) => {
const {setLevelChoice, setGoalChoice, levelChoice, goalChoice} =
useLevelChoice();
const [levelSelected, setLevelSelected] = useState<Level>(levelChoice);
const [goalSelected, setGoalSelected] = useState<Goal>(goalChoice);

const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault();
setLevelChoice(levelSelected);
setGoalChoice(goalSelected);
handleClose();
};

return (
<div className={styles.popup}>
<button className={styles.closeButton} onClick={handleClose}>
Fermer
</button>
<form onSubmit={handleSubmit}>
<div>
<h2>Niveau de connaissances</h2>
{LEVELS.map((value) => (
<InputRadio
key={value}
label={value}
name="level"
value={value}
defaultValue={levelSelected}
handleChange={() => setLevelSelected(value)}
/>
))}
</div>
<div>
<h2>Objectif de voyage</h2>
{GOALS.map((value) => (
<InputRadio
key={value}
label={value}
name="goal"
value={value}
defaultValue={goalSelected}
handleChange={() => setGoalSelected(value)}
/>
))}
</div>
<input type="submit" value="Valider" />
</form>
</div>
);
};

export default LevelChoicePopup;
29 changes: 29 additions & 0 deletions src/components/LevelChoice/levelChoice.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use client';
import React, {useState} from 'react';

import {useLevelChoice} from '../../context/LevelChoiceContext';
import LevelChoiceButton from './LevelButton/LevelChoiceButton';
import LevelChoicePopup from './LevelPopup/LevelPopup';

const LevelChoice = () => {
const {levelChoice, goalChoice} = useLevelChoice();
const [isOn, setIsOn] = useState(false);
const handleClick = () => {
setIsOn(true);
};

const handleClose = () => {
setIsOn(false);
};

return (
<div>
<h3>Connaissances : {levelChoice}</h3>
<h3>Objectif: {goalChoice}</h3>
<LevelChoiceButton onClick={handleClick} />
{isOn && <LevelChoicePopup handleClose={handleClose} />}
</div>
);
};

export default LevelChoice;
33 changes: 33 additions & 0 deletions src/context/LevelChoiceContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use client';
import React, {createContext, useState, useContext} from 'react';

export type Level = 'Débutant' | 'Intermédiaire' | 'Avancé';
export type Goal = 'Tourisme' | 'Long-séjour' | 'Expatrié';

export const LevelChoiceContext = createContext({
levelChoice: 'Débutant' as Level,
goalChoice: 'Tourisme' as Goal,
setLevelChoice: (levelChoice: Level) => {},
setGoalChoice: (goalChoice: Goal) => {},
});

export const useLevelChoice = () => useContext(LevelChoiceContext);

type LevelChoiceProviderProps = {
children: React.ReactNode;
};

export const LevelChoiceProvider: React.FC<LevelChoiceProviderProps> = ({
children,
}) => {
const [levelChoice, setLevelChoice] = useState<Level>('Débutant'); // Specify the type as Level
const [goalChoice, setGoalChoice] = useState<Goal>('Tourisme'); // Specify the type as Goal

return (
<LevelChoiceContext.Provider
value={{levelChoice, setLevelChoice, goalChoice, setGoalChoice}}
>
{children}
</LevelChoiceContext.Provider>
);
};