-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1a128bb
commit ab150e3
Showing
11 changed files
with
361 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import { ChangeEvent, useCallback, useState } from "react" | ||
import { EditLanguageType, Language } from "@/store/useI18nState" | ||
import { DialogClose } from "@radix-ui/react-dialog" | ||
|
||
import { Button } from "@/components/ui/button" | ||
import { | ||
Dialog, | ||
DialogContent, | ||
DialogFooter, | ||
DialogHeader, | ||
DialogTitle, | ||
DialogTrigger, | ||
} from "@/components/ui/dialog" | ||
import { Input } from "@/components/ui/input" | ||
import { Label } from "@/components/ui/label" | ||
|
||
type Props = { | ||
language: Language | ||
editLanguage: (language: EditLanguageType) => void | ||
deleteLanguage: (language: Language) => void | ||
} | ||
|
||
const EditLanguage = (props: Props) => { | ||
const { language, editLanguage, deleteLanguage } = props | ||
|
||
const [languageName, setLanguageName] = useState(language.lang) | ||
const [shortName, setShortName] = useState(language.short) | ||
|
||
const handleChangeLanguageName = useCallback( | ||
(e: ChangeEvent<HTMLInputElement>) => { | ||
setLanguageName(e.target.value) | ||
}, | ||
[] | ||
) | ||
|
||
const handleChangeShortName = useCallback( | ||
(e: ChangeEvent<HTMLInputElement>) => { | ||
setShortName(e.target.value) | ||
}, | ||
[] | ||
) | ||
|
||
const reset = useCallback(() => { | ||
setLanguageName("") | ||
setShortName("") | ||
}, []) | ||
|
||
const onSubmit = useCallback(() => { | ||
editLanguage({ | ||
exShortName: language.short, | ||
lang: languageName, | ||
short: shortName, | ||
}) | ||
reset() | ||
}, [editLanguage, language.short, languageName, reset, shortName]) | ||
|
||
return ( | ||
<Dialog> | ||
<DialogTrigger asChild> | ||
<button className="t-button"> | ||
[{language.short}] {language.lang} | ||
</button> | ||
</DialogTrigger> | ||
<DialogContent className="sm:max-w-[425px]"> | ||
<DialogHeader> | ||
<DialogTitle>Edit language: {language.lang}</DialogTitle> | ||
</DialogHeader> | ||
<div className="grid gap-4 py-4"> | ||
<div className="grid grid-cols-4 items-center gap-4"> | ||
<Label htmlFor="name" className="text-right"> | ||
Name | ||
</Label> | ||
<Input | ||
id="languageName" | ||
placeholder="English" | ||
className="col-span-3" | ||
data-1p-ignore | ||
value={languageName} | ||
onChange={handleChangeLanguageName} | ||
/> | ||
</div> | ||
<div className="grid grid-cols-4 items-center gap-4"> | ||
<Label htmlFor="username" className="text-right"> | ||
Short name (filename) | ||
</Label> | ||
<Input | ||
id="shortName" | ||
placeholder="en" | ||
className="col-span-3" | ||
data-1p-ignore | ||
value={shortName} | ||
onChange={handleChangeShortName} | ||
/> | ||
</div> | ||
</div> | ||
<DialogFooter className="sm:justify-between"> | ||
<DialogClose asChild> | ||
<Button | ||
type="button" | ||
variant="destructive" | ||
className="mt-4 sm:mt-0" | ||
onClick={() => { | ||
deleteLanguage(language) | ||
}} | ||
> | ||
Delete | ||
</Button> | ||
</DialogClose> | ||
<DialogClose asChild> | ||
<Button onClick={onSubmit}>Edit language</Button> | ||
</DialogClose> | ||
</DialogFooter> | ||
</DialogContent> | ||
</Dialog> | ||
) | ||
} | ||
|
||
export default EditLanguage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import { ChangeEvent, useCallback, useState } from "react" | ||
import { Language } from "@/store/useI18nState" | ||
import { DialogClose } from "@radix-ui/react-dialog" | ||
|
||
import { Button } from "@/components/ui/button" | ||
import { | ||
Dialog, | ||
DialogContent, | ||
DialogFooter, | ||
DialogHeader, | ||
DialogTitle, | ||
DialogTrigger, | ||
} from "@/components/ui/dialog" | ||
import { Input } from "@/components/ui/input" | ||
import { Label } from "@/components/ui/label" | ||
|
||
type Props = { | ||
addLanguage: (language: Language) => void | ||
} | ||
|
||
const AddNewLanguage = (props: Props) => { | ||
const { addLanguage } = props | ||
|
||
const [languageName, setLanguageName] = useState("") | ||
const [shortName, setShortName] = useState("") | ||
|
||
const handleChangeLanguageName = useCallback( | ||
(e: ChangeEvent<HTMLInputElement>) => { | ||
setLanguageName(e.target.value) | ||
}, | ||
[] | ||
) | ||
|
||
const handleChangeShortName = useCallback( | ||
(e: ChangeEvent<HTMLInputElement>) => { | ||
setShortName(e.target.value) | ||
}, | ||
[] | ||
) | ||
|
||
const reset = useCallback(() => { | ||
setLanguageName("") | ||
setShortName("") | ||
}, []) | ||
|
||
const onSubmit = useCallback(() => { | ||
addLanguage({ | ||
lang: languageName, | ||
short: shortName, | ||
}) | ||
reset() | ||
}, [addLanguage, languageName, reset, shortName]) | ||
|
||
return ( | ||
<Dialog> | ||
<DialogTrigger asChild> | ||
<button className="t-button"> | ||
<svg | ||
className="h-3.5 w-3.5" | ||
fill="currentColor" | ||
viewBox="0 0 20 20" | ||
xmlns="http://www.w3.org/2000/svg" | ||
aria-hidden="true" | ||
> | ||
<path | ||
clipRule="evenodd" | ||
fillRule="evenodd" | ||
d="M10 3a1 1 0 011 1v5h5a1 1 0 110 2h-5v5a1 1 0 11-2 0v-5H4a1 1 0 110-2h5V4a1 1 0 011-1z" | ||
/> | ||
</svg> | ||
Add language | ||
</button> | ||
</DialogTrigger> | ||
<DialogContent className="sm:max-w-[425px]"> | ||
<DialogHeader> | ||
<DialogTitle>New language</DialogTitle> | ||
</DialogHeader> | ||
<div className="grid gap-4 py-4"> | ||
<div className="grid grid-cols-4 items-center gap-4"> | ||
<Label htmlFor="name" className="text-right"> | ||
Name | ||
</Label> | ||
<Input | ||
id="languageName" | ||
placeholder="English" | ||
className="col-span-3" | ||
data-1p-ignore | ||
value={languageName} | ||
onChange={handleChangeLanguageName} | ||
/> | ||
</div> | ||
<div className="grid grid-cols-4 items-center gap-4"> | ||
<Label htmlFor="username" className="text-right"> | ||
Short name (filename) | ||
</Label> | ||
<Input | ||
id="shortName" | ||
placeholder="en" | ||
className="col-span-3" | ||
data-1p-ignore | ||
value={shortName} | ||
onChange={handleChangeShortName} | ||
/> | ||
</div> | ||
</div> | ||
<DialogFooter> | ||
<DialogClose asChild> | ||
<Button onClick={onSubmit}>Add language</Button> | ||
</DialogClose> | ||
</DialogFooter> | ||
</DialogContent> | ||
</Dialog> | ||
) | ||
} | ||
|
||
export default AddNewLanguage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.