Skip to content

Commit

Permalink
Merge branch 'develop' into feat/redesign-synthesis
Browse files Browse the repository at this point in the history
  • Loading branch information
Baboo7 authored Jun 28, 2023
2 parents c1c869e + 087ba80 commit 2863813
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 60 deletions.
74 changes: 63 additions & 11 deletions packages/client/src/modules/common/components/Button/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,43 +1,95 @@
import { Button as ButtonLib, CircularProgress } from "@mui/material";
import { Button as ButtonLib, CircularProgress, useTheme } from "@mui/material";
import { useMemo } from "react";
import { useNavigate } from "react-router-dom";
import { Icon, IconName } from "../Icon";
import { Typography } from "../Typography";

export { Button };

interface ButtonProps {
type?: "primary" | "secondary";
htmlType?: "button" | "submit";
disabled?: boolean;
loading?: boolean;
onClick: () => void | Promise<void>;
to?: string;
iconName?: IconName;
onClick?: () => void | Promise<void>;
children: React.ReactNode;
}

function Button({
type = "primary",
htmlType = "button",
disabled = false,
loading = false,
onClick,
to,
iconName,
onClick: onClickProp,
children,
}: ButtonProps) {
const navigate = useNavigate();
const theme = useTheme();

const buttonProps = useMemo(() => {
if (disabled) {
return {
props: {
variant: "contained",
},
sx: {
backgroundColor: `${theme.palette.components.button.disabled.backgroundColor} !important`,
color: `${theme.palette.components.button.disabled.color} !important`,
},
};
}
if (type === "primary") {
return {
color: "secondary",
variant: "contained",
props: {
variant: "contained",
color: "secondary",
},
};
}
return {
color: "primary",
props: {
color: "primary",
},
};
}, [type]);
}, [disabled, type]);
const loaderColor = useMemo(
() => (type === "primary" ? "primary" : "secondary"),
[type]
);

const onClick = useMemo(() => {
if (to) {
return () => navigate(to);
}
return onClickProp;
}, [to, navigate, onClickProp]);

return (
<ButtonLib {...(buttonProps as any)} disabled={loading} onClick={onClick}>
{loading && (
<CircularProgress color={loaderColor} size={16} sx={{ mr: 1 }} />
<ButtonLib
type={htmlType}
{...((buttonProps.props || {}) as any)}
disabled={loading || disabled}
onClick={onClick}
sx={{
...(buttonProps.sx || {}),
display: "flex",
gap: 1,
}}
>
{loading && <CircularProgress color={loaderColor} size={16} />}
{iconName && !loading && (
<Icon
name={iconName}
sx={{ width: "1rem", height: "1rem", color: buttonProps.sx?.color }}
/>
)}
{children}
<Typography as="span" sx={{ color: buttonProps.sx?.color }}>
{children}
</Typography>
</ButtonLib>
);
}
2 changes: 2 additions & 0 deletions packages/client/src/modules/common/components/Icon/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {
Microwave,
North,
PieChart,
RocketLaunch,
Shield,
South,
TipsAndUpdates,
Expand Down Expand Up @@ -86,6 +87,7 @@ const ICONS = {
impactful: Whatshot,
information: Info,
"info-card": IconImgFactory({ asset: "info_icon.svg" }),
launch: RocketLaunch,
lock: Lock,
"lock-open": LockOpen,
"mark-circle": Cancel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const CustomDivider = styled(Divider)(({ theme }) => ({
width: "100%",
},
"&::before, &::after": {
borderColor: theme.palette.secondary.light,
borderColor: "#ffffff",
},
[theme.breakpoints.down("sm")]: {
".MuiDivider-wrapper": {
Expand Down
92 changes: 46 additions & 46 deletions packages/client/src/modules/play/MyGames/MyGames.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
import { trim } from "lodash";
import { Link } from "react-router-dom";
import {
Box,
Button,
CircularProgress,
Grid,
TextField,
Typography,
} from "@mui/material";
import { Box, CircularProgress, Grid, TextField } from "@mui/material";
import { Controller, useForm } from "react-hook-form";
import { useMutation, useQuery, useQueryClient } from "react-query";
import { ErrorAlert, SuccessAlert } from "../../alert";
import { ErrorAlert } from "../../alert";
import { PlayBox } from "../Components";
import {
CustomContainer,
CustomDivider,
CustomPaper,
GameItemHost,
JoinGameInputWrapper,
} from "./styles";
} from "./MyGames.styles";
import { IGame } from "../../../utils/types";
import { handleApiError, http } from "../../../utils/request";
import { useTranslation } from "../../translations/useTranslation";
import { Icon } from "../../common/components/Icon";
import { Typography } from "../../common/components/Typography";
import { useAlerts } from "../../alert/AlertProvider";
import { Button } from "../../common/components/Button";

export { MyGames };

Expand All @@ -31,10 +25,12 @@ interface Registration {
}

function MyGames() {
const { t } = useTranslation();

return (
<CustomContainer maxWidth="lg">
<Typography variant="h3" color="secondary">
Mes ateliers
<Typography variant="h3" color="#ffffff">
{t("page.games-list.title")}
</Typography>
<CustomDivider>
<JoinGame />
Expand All @@ -59,52 +55,37 @@ function GameItem({ game }: { game: IGame }) {
{game.status === "draft" && (
<Grid item display="flex" xs={2}>
<Button
component={Link}
color="secondary"
variant="contained"
iconName="settings"
to={`/play/games/${game.id}/personalize/choice`}
sx={{ ml: "auto" }}
>
<Icon name="settings" sx={{ mr: 2 }} />
Préparer l'atelier
{t("cta.prepare-game")}
</Button>
</Grid>
)}
{game.status === "ready" && (
<Grid item display="flex" xs={2}>
<Button
variant="contained"
disabled
sx={{ ml: "auto", backgroundColor: "#AFAFAF !important" }}
>
<Icon name="access-time" sx={{ mr: 2, color: "white" }} />
<Typography sx={{ color: "white" }}>Pas démarré</Typography>
<Button disabled iconName="access-time">
{t("game.status.not-started")}
</Button>
</Grid>
)}
{game.status === "playing" && (
<Grid item display="flex" xs={2}>
<Button
component={Link}
color="secondary"
variant="contained"
iconName="videogame-controller"
to={`/play/games/${game.id}/persona`}
sx={{ ml: "auto" }}
>
<Icon name="videogame-controller" sx={{ mr: 2 }} /> Jouer
{t("cta.play-game")}
</Button>
</Grid>
)}
{game.status === "finished" && (
<Grid item display="flex" xs={2}>
<Button
component={Link}
color="secondary"
variant="contained"
iconName="synthesis"
to={`/play/games/${game.id}/persona/actions`}
sx={{ ml: "auto" }}
>
<Icon name="synthesis" sx={{ mr: 2 }} /> {t("cta.read-synthesis")}
{t("cta.read-synthesis")}
</Button>
</Grid>
)}
Expand All @@ -114,6 +95,8 @@ function GameItem({ game }: { game: IGame }) {
}

function MyGamesList() {
const { t } = useTranslation();

const query = useQuery("/api/games/played-games", () => {
return http.get<undefined, { data: { games: any[] } }>(
"/api/games/played-games"
Expand All @@ -135,10 +118,11 @@ function MyGamesList() {
return (
<Box sx={{ mt: 4 }}>
{currentGames.length > 0 &&
buildGameList(currentGames, "Ateliers en cours")}
{draftGames.length > 0 && buildGameList(draftGames, "Prochains ateliers")}
buildGameList(currentGames, t("page.games-list.ongoing-list.title"))}
{draftGames.length > 0 &&
buildGameList(draftGames, t("page.games-list.upcoming-list.title"))}
{finishedGames.length > 0 &&
buildGameList(finishedGames, "Ateliers terminés")}
buildGameList(finishedGames, t("page.games-list.finished-list.title"))}
</Box>
);
}
Expand All @@ -147,7 +131,7 @@ function buildGameList(games: IGame[], title: string) {
return (
<>
<Box>
<Typography textAlign={"center"} variant="h5" color="secondary" mt={6}>
<Typography textAlign={"center"} variant="h5" color="#ffffff" mt={6}>
{title}
</Typography>
</Box>
Expand All @@ -161,12 +145,13 @@ function buildGameList(games: IGame[], title: string) {
}

function JoinGame() {
const { control, handleSubmit } = useForm({
const { control, handleSubmit, setValue } = useForm({
defaultValues: {
gameCode: "",
},
});
const { t } = useTranslation();
const { enqueueAlert } = useAlerts();

const queryClient = useQueryClient();

Expand All @@ -182,14 +167,26 @@ function JoinGame() {
onSuccess: async (res) => {
queryClient.invalidateQueries("/api/games/played-games");
queryClient.invalidateQueries(`/api/games/${res.data.gameId}/players`);
setValue("gameCode", "");
enqueueAlert({
severity: "success",
message: t("message.success.game-joined"),
});
},
}
);

const onValid = (registration: Registration) => mutation.mutate(registration);
const onSubmit = (registration: Registration) => {
if (!registration.gameCode) {
return;
}

mutation.mutate(registration);
};

return (
<CustomPaper>
<form onSubmit={handleSubmit(onValid)}>
<form onSubmit={handleSubmit(onSubmit)}>
<JoinGameInputWrapper>
<Controller
control={control}
Expand All @@ -206,7 +203,11 @@ function JoinGame() {
/>
)}
/>
<Button type="submit" variant="contained">
<Button
htmlType="submit"
iconName="launch"
loading={mutation.isLoading}
>
{t("cta.join-game")}
</Button>
</JoinGameInputWrapper>
Expand All @@ -223,7 +224,6 @@ function JoinGame() {
})}
/>
)}
{mutation.isSuccess && <SuccessAlert />}
</CustomPaper>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ function PlayLayoutHeader() {
/>
<Box className="flex items-center">
<Typography
className="grow "
className="grow"
component="h1"
variant="h6"
color="inherit"
color="#ffffff"
noWrap
>
{userName}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
"cta.lock-forms": "Verrouiller les formulaires",
"cta.no": "Non",
"cta.open-info-card": "Ouvrir la carte",
"cta.play-game": "Jouer",
"cta.prepare-game": "Préparer l'atelier",
"cta.read-synthesis": "Voir la synthèse",
"cta.read-terms-of-use": "Lire les conditions d'utilisation",
"cta.send-magic-link": "Envoyez moi un lien de connexion",
Expand Down Expand Up @@ -52,6 +54,7 @@
"message.success.copied": "Copiée !",
"message.success.draft-saved": "Brouillon sauvegardé",
"message.success.form-validated": "Formulaire validé",
"message.success.game-joined": "Vous avez rejoint l'atelier avec succès",
"message.success.sign-in.user-authenticated": "Connexion réussie",

"modal.remove-player.title": "Voulez-vous supprimer le joueur ?",
Expand Down Expand Up @@ -92,6 +95,10 @@
"page.login.description": "Si vous avez déjà un compte :",
"page.login.signup-section.title": "Si vous n’avez pas encore de compte :",
"page.login.signup-section.cta": "Créer un compte",
"page.games-list.title": "Mes ateliers",
"page.games-list.finished-list.title": "Ateliers terminés",
"page.games-list.ongoing-list.title": "Ateliers en cours",
"page.games-list.upcoming-list.title": "Prochains ateliers",
"page.player.statistics.tabs.energy-balance.label": "Équilibre énergétique",
"page.player.statistics.tabs.energy-balance.graphs.details.title": "Décomposition de la pile {{stackName}}",
"page.player.statistics.tabs.materials.label": "Matériaux",
Expand Down Expand Up @@ -280,6 +287,7 @@

"game.status.draft": "Brouillon",
"game.status.finished": "Terminé",
"game.status.not-started": "Pas démarré",
"game.status.playing": "En cours",
"game.status.ready": "Prêt",

Expand Down
Loading

0 comments on commit 2863813

Please sign in to comment.