Skip to content

Commit

Permalink
Merge pull request #13 from newrice/dev
Browse files Browse the repository at this point in the history
[fix] カテゴリが存在しない時でもカテゴリ追加可能に
  • Loading branch information
newrice authored Feb 21, 2021
2 parents 9cf8bce + a128bdf commit 4064555
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 45 deletions.
48 changes: 27 additions & 21 deletions src/features/categories/CategoryList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import {
SortableElement,
SortableHandle,
} from "react-sortable-hoc";
import { IconButton, SvgIcon } from "@material-ui/core";
import { Button, IconButton, SvgIcon } from "@material-ui/core";
import DragHandleIcon from "@material-ui/icons/DragHandle";
import AddIcon from "@material-ui/icons/Add";
import clone from "lodash/cloneDeep";
import {
endAddornmentClass,
Expand Down Expand Up @@ -82,29 +83,34 @@ const CategoryList = ({

return (
// divがないとsortableできない
<div>
{items.map((category, index) =>
isN999(category) ? (
<div>
<DragHandle iconElem={<SvgIcon />} disabled />
<N999CategoryItem
<>
<div>
{items.map((category, index) =>
isN999(category) ? (
<div>
<DragHandle iconElem={<SvgIcon />} disabled />
<N999CategoryItem
key={`category-item-${category.id}`}
item={category}
onAddClick={handleAdd}
/>
</div>
) : (
<SortableNormal
key={`category-item-${category.id}`}
item={category}
onAddClick={handleAdd}
index={index}
onChangeName={handleNameChange(index)}
onDisableClick={handleDisableClick(index, !category.disabled)}
onRemoveClick={handleRemoveClick(index)}
/>
</div>
) : (
<SortableNormal
key={`category-item-${category.id}`}
item={category}
index={index}
onChangeName={handleNameChange(index)}
onDisableClick={handleDisableClick(index, !category.disabled)}
onRemoveClick={handleRemoveClick(index)}
/>
),
)}
</div>
),
)}
</div>
<Button onClick={handleAdd} size="small">
<AddIcon />
</Button>
</>
);
};

Expand Down
1 change: 1 addition & 0 deletions src/features/categories/categoriesSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { RootState } from "../../app/rootReducer";
import { AppThunk } from "../../app/store";
import { ICategory } from "../../types";
import { isApiError } from "../../utils";
// import { categoriesData } from "../../__mock__/data";

export const initialState: ICategory[] = [];

Expand Down
2 changes: 1 addition & 1 deletion src/features/categories/controller.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const CategoriesController = (): JSX.Element => {

useEffect(() => {
dispatch(fetchCategories(currentGroup.id));
}, [dispatch, fetchCategories, refresh, currentGroup]);
}, [refresh]);

const responseHandler = (
res: IApiResponseBase<undefined>,
Expand Down
1 change: 0 additions & 1 deletion src/features/costs/components/EditCostForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const EditCostForm = React.memo(
onRequestStart,
onRequestEnd,
}: IEditCostForm): JSX.Element => {
console.log("*** EditCostForm");
const { t } = useTranslation();
const [cost, setCost] = useState<ICostResponse | null>(item);
useEffect(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/features/costs/components/NewCostForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const NewCostForm = React.memo(
onRequestStart,
onRequestEnd,
}: INewCostForm): JSX.Element => {
console.log("*** NewCostDetailForm");
// console.log("*** NewCostDetailForm");
const { t } = useTranslation();
const [cost, setCost] = useState<ICost>(baseCost(currentUserId));

Expand Down
7 changes: 6 additions & 1 deletion src/features/costs/components/SummaryUser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const getPaymentLabelKey = (payment: number) => {
return str;
};

const copyButtonClass = "margin-rl-8";

const equaler = (costs: ICost[], length: number) => {
const all = getTotal(costs);
const num = Math.floor(all / length);
Expand Down Expand Up @@ -55,7 +57,10 @@ export class UserSummary extends AbstractSumary {
<Typography key={`summary-user-${user.id}`}>
{getUserPaymentString(user.id)}
</Typography>
<IconButton onClick={this.handleCopy(user.id)}>
<IconButton
onClick={this.handleCopy(user.id)}
className={copyButtonClass}
>
<FileCopyIcon />
</IconButton>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/features/costs/list/NewCostDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const paperClass = "underlay-paper-base input-dialog-base";

const NewCostDialog = React.memo((props: INewCostForm): JSX.Element => {
const [open, setOpen] = useState<boolean>(false);
console.log("*** NewCostDialog");
// console.log("*** NewCostDialog");
const handleOpen = useCallback(() => {
setOpen(true);
}, []);
Expand Down
2 changes: 1 addition & 1 deletion src/features/group/groupSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const fetchCurrentGroupUsers = (
const { error } = isApiError(repoDetails, true);
if (!error) {
const { body } = repoDetails;
if (body && !isEmpty(body) && isArray(body)) {
if (body && !isEmpty(body.users) && isArray(body.users)) {
dispatch(setCurrentGroupUser(body.users as IUser[]));
} else {
dispatch(setCurrentGroupUser(initialState.currentGroupUsers));
Expand Down
6 changes: 3 additions & 3 deletions src/features/group/view/GroupAdd.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useCallback, useState } from "react";
import { IconButton } from "@material-ui/core";
import { Button } from "@material-ui/core";
import SaveIcon from "@material-ui/icons/Save";
import { GroupNameField } from "./GroupNameTextField";
import { IRequestHandler } from "../../../types";
Expand All @@ -25,9 +25,9 @@ export const GroupAdd = ({
onNameChange={handleNameChange}
className={formFieldCommonClass}
/>
<IconButton disabled={!name} onClick={handleAdd}>
<Button disabled={!name} onClick={handleAdd}>
<SaveIcon />
</IconButton>
</Button>
</>
);
};
Expand Down
9 changes: 1 addition & 8 deletions src/features/group/view/GroupDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ import GroupAdd from "./GroupAdd";

const drawerClass = clsx("border-top-radius");
const formClass = clsx("column-container");
const rowClass = clsx(
"row-container",
"jc-center-container",
"ai-flex-end-container",
);

type GroupDrawer = "Add" | "Edit" | "Exit" | "Invite" | "List";

Expand All @@ -35,9 +30,7 @@ const Drawer = ({ open, onClose, children }: IDrawer) => (
className: drawerClass,
}}
>
<div className={formClass}>
<div className={rowClass}>{children}</div>
</div>
<div className={formClass}>{children}</div>
</InsideAppDrawer>
);

Expand Down
16 changes: 12 additions & 4 deletions src/features/group/view/GroupEdit.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import { Button, IconButton, makeStyles, Theme } from "@material-ui/core";
import { Button, makeStyles, Theme } from "@material-ui/core";
import SaveIcon from "@material-ui/icons/Save";
import clsx from "clsx";
import { GroupNameField } from "./GroupNameTextField";
import { IGroup, IRequestHandler } from "../../../types";
import { edit } from "./functions";
Expand All @@ -13,6 +14,7 @@ interface IGroupEdit extends IRequestHandler {
}

const rowClass = "row-container jc-center-container";
const buttonClass = "flex-auto margin-tb-8";
const formFieldCommonClass = "input-field-base margin-tb-8";

const useStyles = makeStyles((theme: Theme) => ({
Expand Down Expand Up @@ -58,21 +60,27 @@ export const GroupEdit = ({
onNameChange={handleNameChange}
className={formFieldCommonClass}
/>
<IconButton disabled={!newName} onClick={handleSavename}>
<Button
size="small"
disabled={!newName}
onClick={handleSavename}
className={buttonClass}
>
<SaveIcon />
</IconButton>
</Button>
<div className={rowClass}>
<Button
onClick={handleExitClick}
variant="outlined"
className={classes.exitButton}
className={clsx(buttonClass, classes.exitButton)}
>
{t("LABEL_EXIT_GROUP")}
</Button>
<Button
onClick={handleInviteClick}
variant="outlined"
color="secondary"
className={buttonClass}
>
{t("LABEL_INVITE")}
</Button>
Expand Down
9 changes: 7 additions & 2 deletions src/features/group/view/GroupList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { useDispatch, useSelector } from "react-redux";
import { Button, List } from "@material-ui/core";
import AddIcon from "@material-ui/icons/Add";
import GroupListItem from "./GroupListItem";
import { selectCurrentGroup, setCurrentGroup } from "../groupSlice";
import {
selectCurrentGroup,
setCurrentGroup,
setIsGroupDialogOpen,
} from "../groupSlice";
import { selectCurrentUser } from "../../user/userSlice";
import { IGroup } from "../../../types";
import { isEqual } from "../../../utils";
Expand All @@ -20,10 +24,11 @@ export const GroupList = React.memo(
const currentGroup = useSelector(selectCurrentGroup);
const handleSelect = useCallback((group: IGroup) => {
dispatch(setCurrentGroup(group));
dispatch(setIsGroupDialogOpen(false));
}, []);
return (
<>
<List component="nav" aria-label="contacts">
<List style={{ width: "100%" }}>
{groups.map(group => (
<GroupListItem
key={`group-list-${group.id}`}
Expand Down
2 changes: 1 addition & 1 deletion src/features/i18n/resource_ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const ja: II18n = {
LABEL_LOGIN: "ログイン",
LABEL_SIGNUP: "サインアップ",
LABEL_INVITE: "招待",
LABEL_EXIT_GROUP: "退会する",
LABEL_EXIT_GROUP: "退会",
LABEL_ACTIVATION: "有効化",
LABEL_INVALIDATION: "無効化",
// menu labels
Expand Down

0 comments on commit 4064555

Please sign in to comment.