File tree Expand file tree Collapse file tree 3 files changed +60
-0
lines changed
components/organisms/products Expand file tree Collapse file tree 3 files changed +60
-0
lines changed Original file line number Diff line number Diff line change
1
+ import BulkImportButton from '@/components/organisms/products/bulk-import-button'
2
+ import type { Meta , StoryObj } from '@storybook/react'
3
+
4
+ const meta : Meta < typeof BulkImportButton > = {
5
+ title : 'organisms/products/bulk-import-button' ,
6
+ component : BulkImportButton ,
7
+ parameters : {
8
+ // Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout
9
+ layout : 'centered' ,
10
+ } ,
11
+ tags : [ 'autodocs' ] ,
12
+ }
13
+
14
+ export default meta
15
+
16
+ type Story = StoryObj < typeof BulkImportButton >
17
+
18
+ /**
19
+ * 一括登録ボタン
20
+ */
21
+ export const Default : Story = {
22
+ args : { } ,
23
+ }
Original file line number Diff line number Diff line change
1
+ import StandardButton from '@/components/atoms/buttons/standard-button'
2
+ import { parse } from '@/libs/papaparse'
3
+ import { validationSchema } from '@/reducks/products/types'
4
+ import React , { ChangeEvent , useCallback } from 'react'
5
+ import { z } from 'zod'
6
+
7
+ const BulkImportButton = React . memo ( function BulkImportButton ( ) {
8
+ const inputRef = React . useRef < HTMLInputElement > ( null )
9
+ const onChange = useCallback ( async ( event : ChangeEvent < HTMLInputElement > ) => {
10
+ const file = event . target . files ?. [ 0 ]
11
+ if ( ! file ) return
12
+
13
+ const parsed = await parse ( file , z . array ( validationSchema ) )
14
+ alert ( JSON . stringify ( parsed ) )
15
+ } , [ ] )
16
+
17
+ const upload = useCallback ( ( ) => {
18
+ inputRef . current ?. click ( )
19
+ } , [ ] )
20
+
21
+ return (
22
+ < div >
23
+ < StandardButton onclick = { upload } name = "一括登録" />
24
+ < input
25
+ hidden
26
+ type = "file"
27
+ accept = ".csv"
28
+ ref = { inputRef }
29
+ onChange = { onChange }
30
+ />
31
+ </ div >
32
+ )
33
+ } )
34
+
35
+ export default BulkImportButton
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import ProductAdditionForm from '@/components/molecules/forms/products/product-a
4
4
import ProductDeletionForm from '@/components/molecules/forms/products/product-deletion-form'
5
5
import ProductEditingForm from '@/components/molecules/forms/products/product-editing-form'
6
6
import Modal from '@/components/molecules/modals/modal'
7
+ import BulkImportButton from '@/components/organisms/products/bulk-import-button'
7
8
import TenantsTemplate from '@/components/templates/tenants-template'
8
9
import { useProducts } from '@/hooks/use-products'
9
10
import { getProductsAndRefresh } from '@/reducks/products/selectors'
@@ -55,6 +56,7 @@ const ProductList: React.FC = () => {
55
56
< button css = { styles . button } onClick = { ( ) => setIsModalOpen ( true ) } >
56
57
新規作成
57
58
</ button >
59
+ < BulkImportButton />
58
60
59
61
{ isDeleteDialogOpen && productToDelete && (
60
62
< div css = { styles . overlay } >
You can’t perform that action at this time.
0 commit comments