Disable add Profile button when enabled languages are empty

pull/1371/head
LASER-Yi 4 years ago
parent 94dd36d5dc
commit a99c4d5438

@ -8,7 +8,7 @@ import React, {
} from "react"; } from "react";
import { Badge, Button, ButtonGroup } from "react-bootstrap"; import { Badge, Button, ButtonGroup } from "react-bootstrap";
import { Column, TableUpdater } from "react-table"; import { Column, TableUpdater } from "react-table";
import { useProfiles } from "."; import { useEnabledLanguages, useProfiles } from ".";
import { ActionButton, SimpleTable, useShowModal } from "../../components"; import { ActionButton, SimpleTable, useShowModal } from "../../components";
import { useSingleUpdate } from "../components"; import { useSingleUpdate } from "../components";
import { languageProfileKey } from "../keys"; import { languageProfileKey } from "../keys";
@ -18,6 +18,8 @@ import { anyCutoff } from "./options";
const Table: FunctionComponent = () => { const Table: FunctionComponent = () => {
const originalProfiles = useProfiles(); const originalProfiles = useProfiles();
const languages = useEnabledLanguages();
const [profiles, setProfiles] = useState(() => cloneDeep(originalProfiles)); const [profiles, setProfiles] = useState(() => cloneDeep(originalProfiles));
const nextProfileId = useMemo( const nextProfileId = useMemo(
@ -117,6 +119,8 @@ const Table: FunctionComponent = () => {
[] []
); );
const canAdd = languages.length !== 0;
return ( return (
<React.Fragment> <React.Fragment>
<SimpleTable <SimpleTable
@ -126,6 +130,7 @@ const Table: FunctionComponent = () => {
></SimpleTable> ></SimpleTable>
<Button <Button
block block
disabled={!canAdd}
variant="light" variant="light"
onClick={() => { onClick={() => {
const profile = { const profile = {
@ -137,7 +142,7 @@ const Table: FunctionComponent = () => {
showModal("profile", profile); showModal("profile", profile);
}} }}
> >
Add New Profile {canAdd ? "Add New Profile" : "No Enabled Languages"}
</Button> </Button>
<Modal update={updateProfile} modalKey="profile"></Modal> <Modal update={updateProfile} modalKey="profile"></Modal>
</React.Fragment> </React.Fragment>

Loading…
Cancel
Save