Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

募金登録の金額入力フォームにプルダウンを追加する #659

Merged
merged 9 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions view/next-project/src/components/common/Input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,36 @@ interface Props {
onChange?: (e: React.ChangeEvent<HTMLInputElement>) => void;
children?: React.ReactNode;
type?: string;
datalist?: { id: number; name: string }[];
listKey?: string;
enableDatalist?: boolean;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
enableDatalist?: boolean;

好みですが、個人的にはdalalistがあるかどうかで判断できるかなって思いました。

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

datalistlistkeyの存在を同時に確かめたい場合は、一緒にしてしまってもいいと思います

datalist?: {
    key: string;
    data: { id:number; name: string}[];
}

}

function Input(props: Props): JSX.Element {
const className =
'rounded-full border border-primary-1 py-2 px-4' +
(props.className ? ` ${props.className}` : '');
return (
<input
className={clsx(s.input, className)}
placeholder={props.placeholder}
id={props.id}
value={props.value}
onChange={props.onChange}
type={props.type}
>
{props.children}
</input>
<div>
<input
className={clsx(s.input, className)}
placeholder={props.placeholder}
id={props.id}
value={props.value}
onChange={props.onChange}
type={props.type}
list={props.enableDatalist ? props.listKey : undefined}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
list={props.enableDatalist ? props.listKey : undefined}
list={props.datalist && props.listKey}

listにはpropsにdatalistがあれば、props.listkeyを渡すで十分かと思います。

>
{props.children}
</input>
{props.enableDatalist && (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{props.enableDatalist && (
{props.datalist && (

props.datalistがあるかどうかで判断できるかなって思います。

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enableDatalistで切り替えない場合はlistkeyのチェックも入れた方が安全になります

Suggested change
{props.enableDatalist && (
{props.enableDatalist && props.listkey && (

<datalist id={props.listKey}>
{props.datalist?.map((option) => (
<option key={option.id} value={option.name} />
))}
</datalist>
)}
</div>
);
}

Expand Down
10 changes: 9 additions & 1 deletion view/next-project/src/components/fund_information/AddModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Modal, CloseButton, Input, Select, PrimaryButton } from '../common';
import { userAtom } from '@/store/atoms';
import { post } from '@api/fundInformations';
import { BUREAUS } from '@constants/bureaus';
import { DONATION_AMOUNT } from '@constants/donationAmount';
import { Department, FundInformation, Teacher, User } from '@type/common';

interface ModalProps {
Expand Down Expand Up @@ -132,7 +133,14 @@ const OpenAddModal: FC<ModalProps> = (props) => {
</div>
<p className='col-span-1 text-black-600'>金額</p>
<div className='col-span-4 w-full'>
<Input className='w-full' value={formData.price} onChange={handler('price')} />
<Input
className='w-full'
value={formData.price}
onChange={handler('price')}
datalist={DONATION_AMOUNT}
listKey='amoutOptions'
enableDatalist={true}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
enableDatalist={true}

上のように修正すれば消せます。

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ちなみにtrueを渡さなくても

Suggested change
enableDatalist={true}
enableDatalist

のみでtrueのように動作します

/>
</div>
<p className='col-span-1 text-black-600'>備考</p>
<div className='col-span-4 w-full'>
Expand Down
10 changes: 9 additions & 1 deletion view/next-project/src/components/fund_information/EditModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Dispatch, SetStateAction, useEffect, useState, useMemo } from 'react';
import { Modal, Input, Select, CloseButton, PrimaryButton } from '../common';
import { put } from '@api/fundInformations';
import { BUREAUS } from '@constants/bureaus';
import { DONATION_AMOUNT } from '@constants/donationAmount';
import { FundInformation, Teacher, User, Department } from '@type/common';

interface ModalProps {
Expand Down Expand Up @@ -140,7 +141,14 @@ export default function EditModal(props: ModalProps) {
</div>
<p className='col-span-1 text-black-600'>金額</p>
<div className='col-span-4 w-full'>
<Input className='w-full' value={formData.price} onChange={handler('price')} />
<Input
className='w-full'
value={formData.price}
onChange={handler('price')}
datalist={DONATION_AMOUNT}
listKey='amoutOptions'
enableDatalist={true}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
enableDatalist={true}

ここも同様です。

/>
</div>
<p className='col-span-1 text-black-600'>備考</p>
<div className='col-span-4 w-full'>
Expand Down
18 changes: 18 additions & 0 deletions view/next-project/src/constants/donationAmount.ts
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

constantで定数を定義できてて良いと思います!

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export const DONATION_AMOUNT = [
{
id: 1,
name: '1000',
},
{
id: 2,
name: '2000',
},
{
id: 3,
name: '5000',
},
{
id: 4,
name: '10000',
},
];