Skip to content

Commit

Permalink
一括登録ボタンに直接ファイルを指定できるように変更
Browse files Browse the repository at this point in the history
  • Loading branch information
kuramapommel committed Sep 6, 2024
1 parent 1ab54e1 commit 8dafc27
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions sample/src/components/organisms/products/bulk-import-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ import { validationSchema } from '@/reducks/products/types'
import React, { ChangeEvent, useCallback } from 'react'
import { z } from 'zod'

const BulkImportButton = React.memo(function BulkImportButton() {
type Props = {
acceptedFile?: File
}

const BulkImportButton = React.memo(function BulkImportButton({
acceptedFile,
}: Props) {
const inputRef = React.useRef<HTMLInputElement>(null)
const onChange = useCallback(async (event: ChangeEvent<HTMLInputElement>) => {
const file = event.target.files?.[0]
Expand All @@ -15,8 +21,13 @@ const BulkImportButton = React.memo(function BulkImportButton() {
}, [])

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

return (
<div>
Expand Down

0 comments on commit 8dafc27

Please sign in to comment.