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 8 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
34 changes: 24 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,37 @@ interface Props {
onChange?: (e: React.ChangeEvent<HTMLInputElement>) => void;
children?: React.ReactNode;
type?: string;
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.datalist?.key}
>
{props.children}
</input>
{props.datalist?.key && props.datalist?.data && (
<datalist id={props.datalist.key}>
{props.datalist.data.map((option) => (
<option key={option.id} value={option.name} />
))}
</datalist>
)}
Copy link
Collaborator

Choose a reason for hiding this comment

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

datalistが存在すればkeyもdataも存在すると思うので、datalistの存在だけ確認すればいいと思います

Suggested change
{props.datalist?.key && props.datalist?.data && (
<datalist id={props.datalist.key}>
{props.datalist.data.map((option) => (
<option key={option.id} value={option.name} />
))}
</datalist>
)}
{props.datalist && (
<datalist id={props.datalist.key}>
{props.datalist.data.map((option) => (
<option key={option.id} value={option.name} />
))}
</datalist>
)}

</div>
);
}

Expand Down
11 changes: 10 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,15 @@ 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={{
key: 'amoutOptions',
data: DONATION_AMOUNT,
}}
/>
</div>
<p className='col-span-1 text-black-600'>備考</p>
<div className='col-span-4 w-full'>
Expand Down
11 changes: 10 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,15 @@ 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={{
key: 'amoutOptions',
data: DONATION_AMOUNT,
}}
/>
</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',
},
];