Refactors useLocale (#908)
* Removes unused component * Refactors useLocale We don't need to pass the locale prop everywhere * Fixes syntax error * Adds warning for missing localeProps * Simplify i18n utils * Update components/I18nLanguageHandler.tsx Co-authored-by: Mihai C <[email protected]> * Type fixes Co-authored-by: Mihai C <[email protected]>
This commit is contained in:
1 parent
7dd6fdde7a
commit
cfd70172f0
35 files changed
+366
-440
No files matched your search
@@ -17,11 +17,7 @@ import ErrorAlert from "@components/ui/alerts/Error";
|
||||
|
||||
import MemberList from "./MemberList";
|
||||
|
||||
export default function EditTeam(props: {
|
||||
localeProp: string;
|
||||
team: Team | undefined | null;
|
||||
onCloseEdit: () => void;
|
||||
}) {
|
||||
export default function EditTeam(props: { team: Team | undefined | null; onCloseEdit: () => void }) {
|
||||
const [members, setMembers] = useState([]);
|
||||
|
||||
const nameRef = useRef<HTMLInputElement>() as React.MutableRefObject<HTMLInputElement>;
|
||||
@@ -35,7 +31,7 @@ export default function EditTeam(props: {
|
||||
const [inviteModalTeam, setInviteModalTeam] = useState<Team | null | undefined>();
|
||||
const [errorMessage, setErrorMessage] = useState("");
|
||||
const [imageSrc, setImageSrc] = useState<string>("");
|
||||
const { t, locale } = useLocale({ localeProp: props.localeProp });
|
||||
const { t } = useLocale();
|
||||
|
||||
const loadMembers = () =>
|
||||
fetch("/api/teams/" + props.team?.id + "/membership")
|
||||
@@ -235,12 +231,7 @@ export default function EditTeam(props: {
|
||||
</div>
|
||||
<div>
|
||||
{!!members.length && (
|
||||
<MemberList
|
||||
localeProp={locale}
|
||||
members={members}
|
||||
onRemoveMember={onRemoveMember}
|
||||
onChange={loadMembers}
|
||||
/>
|
||||
<MemberList members={members} onRemoveMember={onRemoveMember} onChange={loadMembers} />
|
||||
)}
|
||||
<hr className="mt-6" />
|
||||
</div>
|
||||
@@ -278,7 +269,6 @@ export default function EditTeam(props: {
|
||||
{t("disband_team")}
|
||||
</DialogTrigger>
|
||||
<ConfirmationDialogContent
|
||||
localeProp={locale}
|
||||
variety="danger"
|
||||
title={t("disband_team")}
|
||||
confirmBtnText={t("confirm_disband_team")}
|
||||
@@ -305,11 +295,7 @@ export default function EditTeam(props: {
|
||||
handleClose={closeSuccessModal}
|
||||
/>
|
||||
{showMemberInvitationModal && (
|
||||
<MemberInvitationModal
|
||||
localeProp={locale}
|
||||
team={inviteModalTeam}
|
||||
onExit={onMemberInvitationModalExit}
|
||||
/>
|
||||
<MemberInvitationModal team={inviteModalTeam} onExit={onMemberInvitationModalExit} />
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -6,13 +6,9 @@ import { Team } from "@lib/team";
|
||||
|
||||
import Button from "@components/ui/Button";
|
||||
|
||||
export default function MemberInvitationModal(props: {
|
||||
localeProp: string;
|
||||
team: Team | undefined | null;
|
||||
onExit: () => void;
|
||||
}) {
|
||||
export default function MemberInvitationModal(props: { team: Team | undefined | null; onExit: () => void }) {
|
||||
const [errorMessage, setErrorMessage] = useState("");
|
||||
const { t } = useLocale({ localeProp: props.localeProp });
|
||||
const { t } = useLocale();
|
||||
|
||||
const handleError = async (res: Response) => {
|
||||
const responseData = await res.json();
|
||||
|
||||
@@ -1,16 +1,12 @@
|
||||
import { useLocale } from "@lib/hooks/useLocale";
|
||||
import { Member } from "@lib/member";
|
||||
|
||||
import MemberListItem from "./MemberListItem";
|
||||
|
||||
export default function MemberList(props: {
|
||||
localeProp: string;
|
||||
members: Member[];
|
||||
onRemoveMember: (text: Member) => void;
|
||||
onChange: (text: string) => void;
|
||||
}) {
|
||||
const { locale } = useLocale({ localeProp: props.localeProp });
|
||||
|
||||
const selectAction = (action: string, member: Member) => {
|
||||
switch (action) {
|
||||
case "remove":
|
||||
@@ -24,7 +20,6 @@ export default function MemberList(props: {
|
||||
<ul className="px-4 mb-2 bg-white border divide-y divide-gray-200 rounded">
|
||||
{props.members.map((member) => (
|
||||
<MemberListItem
|
||||
localeProp={locale}
|
||||
onChange={props.onChange}
|
||||
key={member.id}
|
||||
member={member}
|
||||
|
||||
@@ -12,13 +12,12 @@ import Button from "@components/ui/Button";
|
||||
import Dropdown, { DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "../ui/Dropdown";
|
||||
|
||||
export default function MemberListItem(props: {
|
||||
localeProp: string;
|
||||
member: Member;
|
||||
onActionSelect: (text: string) => void;
|
||||
onChange: (text: string) => void;
|
||||
}) {
|
||||
const [member] = useState(props.member);
|
||||
const { t, locale } = useLocale({ localeProp: props.localeProp });
|
||||
const { t } = useLocale();
|
||||
|
||||
return (
|
||||
member && (
|
||||
@@ -80,7 +79,6 @@ export default function MemberListItem(props: {
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
<ConfirmationDialogContent
|
||||
localeProp={locale}
|
||||
variety="danger"
|
||||
title={t("remove_member")}
|
||||
confirmBtnText={t("confirm_remove_member")}
|
||||
|
||||
@@ -1,16 +1,12 @@
|
||||
import { useLocale } from "@lib/hooks/useLocale";
|
||||
import { Team } from "@lib/team";
|
||||
|
||||
import TeamListItem from "./TeamListItem";
|
||||
|
||||
export default function TeamList(props: {
|
||||
localeProp: string;
|
||||
teams: Team[];
|
||||
onChange: () => void;
|
||||
onEditTeam: (text: Team) => void;
|
||||
}) {
|
||||
const { locale } = useLocale({ localeProp: props.localeProp });
|
||||
|
||||
const selectAction = (action: string, team: Team) => {
|
||||
switch (action) {
|
||||
case "edit":
|
||||
@@ -34,7 +30,6 @@ export default function TeamList(props: {
|
||||
<ul className="px-4 mb-2 bg-white border divide-y divide-gray-200 rounded">
|
||||
{props.teams.map((team: Team) => (
|
||||
<TeamListItem
|
||||
localeProp={locale}
|
||||
onChange={props.onChange}
|
||||
key={team.id}
|
||||
team={team}
|
||||
|
||||
@@ -31,14 +31,13 @@ interface Team {
|
||||
}
|
||||
|
||||
export default function TeamListItem(props: {
|
||||
localeProp: string;
|
||||
onChange: () => void;
|
||||
key: number;
|
||||
team: Team;
|
||||
onActionSelect: (text: string) => void;
|
||||
}) {
|
||||
const [team, setTeam] = useState<Team | null>(props.team);
|
||||
const { t, locale } = useLocale({ localeProp: props.localeProp });
|
||||
const { t } = useLocale();
|
||||
|
||||
const acceptInvite = () => invitationResponse(true);
|
||||
const declineInvite = () => invitationResponse(false);
|
||||
@@ -155,7 +154,6 @@ export default function TeamListItem(props: {
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
<ConfirmationDialogContent
|
||||
localeProp={locale}
|
||||
variety="danger"
|
||||
title="Disband Team"
|
||||
confirmBtnText={t("confirm_disband_team")}
|
||||
|
||||
@@ -10,8 +10,8 @@ import Avatar from "@components/ui/Avatar";
|
||||
import Button from "@components/ui/Button";
|
||||
import Text from "@components/ui/Text";
|
||||
|
||||
const Team = ({ team, localeProp }) => {
|
||||
const { t } = useLocale({ localeProp: localeProp });
|
||||
const Team = ({ team }) => {
|
||||
const { t } = useLocale();
|
||||
|
||||
const Member = ({ member }) => {
|
||||
const classes = classnames(
|
||||
|
||||
Reference in new issue
Block a user