Skip to content

Commit 8dafc27

Browse files
committed
一括登録ボタンに直接ファイルを指定できるように変更
1 parent 1ab54e1 commit 8dafc27

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

sample/src/components/organisms/products/bulk-import-button.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@ import { validationSchema } from '@/reducks/products/types'
44
import React, { ChangeEvent, useCallback } from 'react'
55
import { z } from 'zod'
66

7-
const BulkImportButton = React.memo(function BulkImportButton() {
7+
type Props = {
8+
acceptedFile?: File
9+
}
10+
11+
const BulkImportButton = React.memo(function BulkImportButton({
12+
acceptedFile,
13+
}: Props) {
814
const inputRef = React.useRef<HTMLInputElement>(null)
915
const onChange = useCallback(async (event: ChangeEvent<HTMLInputElement>) => {
1016
const file = event.target.files?.[0]
@@ -15,8 +21,13 @@ const BulkImportButton = React.memo(function BulkImportButton() {
1521
}, [])
1622

1723
const upload = useCallback(() => {
24+
if (acceptedFile) {
25+
alert(JSON.stringify(acceptedFile))
26+
// todo ファイルが登録されている場合はそのままアップロードする
27+
return
28+
}
1829
inputRef.current?.click()
19-
}, [])
30+
}, [acceptedFile])
2031

2132
return (
2233
<div>

0 commit comments

Comments
 (0)