Skip to content

Commit fa68531

Browse files
authored
Merge pull request #469 from dzcode-io/467-remove-unnecessary-code-and-dependencies
CHORE: removed unnecessary localization code and dependencies
2 parents e5e826c + de68785 commit fa68531

File tree

51 files changed

+763
-1140
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+763
-1140
lines changed

packages/ui/src/dialog/index.test.tsx renamed to packages/ui/src/contributor-card/dialog/index.test.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import { render, screen } from "@testing-library/react";
22

3-
import { createProjects } from "../__mocks__/create-projects";
4-
import { createRepositories } from "../__mocks__/create-repositories";
5-
import { ContributionsDialog } from ".";
3+
import { createProjects } from "../../__mocks__/create-projects";
4+
import { createRepositories } from "../../__mocks__/create-repositories";
5+
import { ContributionsDialog, ContributionsDialogProps } from ".";
66

77
it("should render a closed dialog on first mount", async () => {
88
const onClose = jest.fn();
9-
const props = {
9+
const props: ContributionsDialogProps = {
1010
onClose: onClose,
1111
open: false,
12-
projects: createProjects(2),
1312
repositories: createRepositories(2),
13+
repositoriesText: "Repositories",
1414
};
1515

1616
const { container } = render(<ContributionsDialog {...props} />);
@@ -19,11 +19,11 @@ it("should render a closed dialog on first mount", async () => {
1919

2020
it("should handle users with no projects", async () => {
2121
const onClose = jest.fn();
22-
const props = {
22+
const props: ContributionsDialogProps = {
2323
onClose: onClose,
2424
open: true,
25-
projects: [],
2625
repositories: createRepositories(2),
26+
repositoriesText: "Repositories",
2727
};
2828

2929
render(<ContributionsDialog {...props} />);
@@ -33,11 +33,11 @@ it("should handle users with no projects", async () => {
3333

3434
it("should handle users with no repositories", async () => {
3535
const onClose = jest.fn();
36-
const props = {
36+
const props: ContributionsDialogProps = {
3737
onClose: onClose,
3838
open: true,
39-
projects: createProjects(2),
4039
repositories: [],
40+
repositoriesText: "Repositories",
4141
};
4242

4343
render(<ContributionsDialog {...props} />);
@@ -47,11 +47,11 @@ it("should handle users with no repositories", async () => {
4747

4848
it("should render a dialog", async () => {
4949
const onClose = jest.fn();
50-
const props = {
50+
const props: ContributionsDialogProps = {
5151
onClose: onClose,
5252
open: true,
53-
projects: createProjects(2),
5453
repositories: createRepositories(2),
54+
repositoriesText: "Repositories",
5555
};
5656

5757
render(<ContributionsDialog {...props} />);

packages/ui/src/dialog/index.tsx renamed to packages/ui/src/contributor-card/dialog/index.tsx

Lines changed: 12 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import ListItem from "@mui/material/ListItem";
88
import ListItemAvatar from "@mui/material/ListItemAvatar";
99
import ListItemText from "@mui/material/ListItemText";
1010
import Typography from "@mui/material/Typography";
11+
import { FC } from "react";
1112

1213
interface ContributionItemProps {
1314
description: string;
@@ -36,7 +37,7 @@ interface ContributionListProps {
3637
const ContributionList = ({ title, items }: ContributionListProps) => {
3738
return (
3839
<>
39-
<Typography variant="h4" component="h2" textAlign="center">
40+
<Typography variant="h4" component="h2" textAlign="center" margin={2}>
4041
{title}
4142
</Typography>
4243
<List>
@@ -48,66 +49,39 @@ const ContributionList = ({ title, items }: ContributionListProps) => {
4849
};
4950

5051
export interface ContributionsDialogProps {
52+
repositoriesText: string;
5153
open: boolean;
52-
projects?: Array<{
53-
slug: string;
54-
image?: string;
55-
title: string;
56-
description?: string;
57-
content?: string;
58-
authors?: string[];
59-
contributors?: string[];
60-
views?: number;
61-
githubURI?: string;
62-
}>;
6354
repositories?: { provider: string; owner: string; repository: string }[];
6455
onClose: () => void;
6556
}
6657

67-
export function ContributionsDialog(props: ContributionsDialogProps) {
68-
const { onClose, open, projects, repositories } = props;
69-
70-
const handleClose = () => {
71-
onClose();
72-
};
73-
58+
export const ContributionsDialog: FC<ContributionsDialogProps> = ({
59+
onClose,
60+
open,
61+
repositories,
62+
repositoriesText,
63+
}) => {
7464
return (
7565
<Dialog
7666
maxWidth="sm"
7767
fullWidth
78-
onClose={handleClose}
68+
onClose={onClose}
7969
aria-labelledby="contribution"
8070
data-testid="contribution-dialog"
8171
open={open}
8272
>
8373
<Grid container rowSpacing={2}>
84-
<Grid item xs={12}>
85-
<DialogTitle
86-
id="contribution"
87-
sx={{ textAlign: "center", fontSize: "typography.h2.fontSize" }}
88-
>
89-
Contributions
90-
</DialogTitle>
91-
</Grid>
9274
<Grid item xs={12}>
9375
{repositories && repositories.length > 0 && (
9476
<ContributionList
95-
title="Repositories"
77+
title={repositoriesText}
9678
items={repositories.map((repository) => ({
9779
label: repository.repository,
9880
}))}
9981
/>
10082
)}
10183
</Grid>
102-
<Grid item xs={12}>
103-
{projects && projects.length > 0 && (
104-
<ContributionList
105-
title="Projects"
106-
items={projects.map((project) => ({ label: project.title }))}
107-
/>
108-
)}
109-
</Grid>
11084
</Grid>
11185
</Dialog>
11286
);
113-
}
87+
};

packages/ui/src/contributor-card/index.test.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,27 @@ it("should render a contributor skeleton ", async () => {
1313

1414
it("should render a contributor card", () => {
1515
const contributor = createContributors(1)[0];
16-
render(<ContributorCard contributor={contributor} />);
16+
render(
17+
<ContributorCard
18+
contributor={contributor}
19+
ctaText="Contributions"
20+
repositoriesText="Repositories"
21+
/>,
22+
);
1723
const username = screen.getByText(contributor.username);
1824

1925
expect(username).toBeInTheDocument();
2026
});
2127

2228
it("should show contributions dialog after Contributions button is clicked", async () => {
2329
const contributor = createContributors(1)[0];
24-
render(<ContributorCard contributor={contributor} />);
30+
render(
31+
<ContributorCard
32+
contributor={contributor}
33+
ctaText="Contributions"
34+
repositoriesText="Repositories"
35+
/>,
36+
);
2537
const button = await screen.findByRole("button", { name: "Contributions" });
2638
userEvent.click(button);
2739

packages/ui/src/contributor-card/index.tsx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Skeleton from "@mui/material/Skeleton";
99
import Typography from "@mui/material/Typography";
1010
import { FC, useState } from "react";
1111

12-
import { ContributionsDialog } from "../dialog";
12+
import { ContributionsDialog } from "./dialog";
1313

1414
const styles = {
1515
root: {
@@ -41,11 +41,17 @@ export const ContributorSkeleton = () => {
4141
);
4242
};
4343

44-
interface ContributorCardProps {
44+
export interface ContributorCardProps {
45+
ctaText: string;
46+
repositoriesText: string;
4547
contributor: ContributorEntity;
4648
}
4749

48-
export const ContributorCard: FC<ContributorCardProps> = ({ contributor }) => {
50+
export const ContributorCard: FC<ContributorCardProps> = ({
51+
contributor,
52+
ctaText,
53+
repositoriesText,
54+
}) => {
4955
const [open, setOpen] = useState(false);
5056
const { avatarUrl, username, repositories } = contributor;
5157
return (
@@ -64,10 +70,15 @@ export const ContributorCard: FC<ContributorCardProps> = ({ contributor }) => {
6470
fullWidth
6571
variant="contained"
6672
>
67-
Contributions
73+
{ctaText}
6874
</Button>
6975
</CardActions>
70-
<ContributionsDialog repositories={repositories} open={open} onClose={() => setOpen(false)} />
76+
<ContributionsDialog
77+
repositoriesText={repositoriesText}
78+
repositories={repositories}
79+
open={open}
80+
onClose={() => setOpen(false)}
81+
/>
7182
</MuiCard>
7283
);
7384
};

packages/ui/src/faq-card/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const FaqCard = ({ title, questions }: FaqCardProps) => {
2424
</Grid>
2525
<Grid item xs={12}>
2626
{questions.map(({ question, answer }, index) => (
27-
<Accordion key={`faq-${index}`} variant="outlined">
27+
<Accordion key={`faq-${index}`} variant="outlined" style={{ marginTop: -1 }}>
2828
<AccordionSummary expandIcon={<ExpandMore />}>
2929
<Typography variant="body1">{question}</Typography>
3030
</AccordionSummary>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import type { VFC } from "react";
2+
3+
type BaseDictionary = Record<string, Record<string, string>>;
4+
5+
export const translationFactory =
6+
<T extends BaseDictionary>(
7+
dictionary: T,
8+
getLanguageCode: () => keyof T[keyof T],
9+
fallbackText = "MISSING_TRANSLATION",
10+
): VFC<
11+
Partial<Record<keyof T, boolean>> & {
12+
k?: keyof T;
13+
r?: Record<string, string>;
14+
}
15+
> =>
16+
// eslint-disable-next-line react/display-name
17+
({ k, r = {}, ...props }) => {
18+
const languageCode = getLanguageCode();
19+
const key = (k as keyof T) || (Object.keys(props)[0] as keyof T);
20+
return <>{replace(dictionary, languageCode, fallbackText, key, r)}</>;
21+
};
22+
23+
export const translationFunctionFactory =
24+
<T extends Record<string, Record<string, string>>>(
25+
dictionary: T,
26+
getLanguageCode: () => keyof T[keyof T],
27+
fallbackText?: string,
28+
): ((k: keyof T, r?: Record<string, string>) => string) =>
29+
(k, r = {}) => {
30+
const languageCode = getLanguageCode();
31+
return replace(dictionary, languageCode, fallbackText, k, r);
32+
};
33+
34+
const replace = <T extends BaseDictionary>(
35+
dictionary: T,
36+
languageCode: keyof T[keyof T],
37+
fallbackText = "MISSING_TRANSLATION",
38+
k: keyof T,
39+
r: Record<string, string> = {},
40+
) => {
41+
const key = k;
42+
let value = dictionary[key]?.[languageCode] || fallbackText;
43+
Object.keys(r).forEach((rKey: keyof typeof r) => {
44+
value = value.replace(RegExp(`${rKey}`), r[rKey]);
45+
});
46+
return value;
47+
};

web/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
"markdown-to-jsx": "^7.1.0",
2727
"react": "^17.0.1",
2828
"react-dom": "^17.0.1",
29-
"react-intl": "^5.20.6",
30-
"react-intl-translations-manager": "^5.0.3",
3129
"react-redux": "^7.2.6",
3230
"react-router-dom": "^5.2.0",
3331
"react-spring": "^8.0.27",

web/src/apps/main/components/card/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export const Card: FC<CardProps> = ({ info }) => {
4747
{info ? (
4848
<>
4949
<CardMedia className={classes.media} image={info.image} title={info.title} />
50-
<CardContent className={classes.content}>
50+
<CardContent dir="ltr" className={classes.content}>
5151
<Typography gutterBottom variant="h6">
5252
{info.title}
5353
</Typography>

web/src/apps/main/components/footer/__snapshots__/footer.spec.tsx.snap

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,14 @@ exports[`components/footer/footer.spec.tsx should render properly 1`] = `
183183
<h6
184184
class="MuiTypography-root makeStyles-categoryTitle-3 MuiTypography-h6"
185185
>
186-
Contact Information
186+
FAQ
187187
</h6>
188188
<a
189189
href="tel:+21367-626-1157"
190190
>
191191
<p
192192
class="MuiTypography-root makeStyles-linkText-2 MuiTypography-body1"
193+
style="direction: ltr; display: inline-block;"
193194
>
194195
+213 06-76-26-11-57
195196
</p>
@@ -206,10 +207,12 @@ exports[`components/footer/footer.spec.tsx should render properly 1`] = `
206207
<p
207208
class="MuiTypography-root makeStyles-linkText-2 MuiTypography-body1"
208209
>
209-
Copyright ©
210-
2020
210+
Copyright ©
211+
212+
2022
211213
<a
212214
href="https://twitter.com/dzcode_io"
215+
style="direction: ltr; display: inline-block;"
213216
>
214217
@dzCode_io
215218
</a>

0 commit comments

Comments
 (0)