-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d8debfe
commit 7933667
Showing
3 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
sample/src/components/organisms/products/bulk-import-button.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import BulkImportButton from '@/components/organisms/products/bulk-import-button' | ||
import type { Meta, StoryObj } from '@storybook/react' | ||
|
||
const meta: Meta<typeof BulkImportButton> = { | ||
title: 'organisms/products/bulk-import-button', | ||
component: BulkImportButton, | ||
parameters: { | ||
// Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout | ||
layout: 'centered', | ||
}, | ||
tags: ['autodocs'], | ||
} | ||
|
||
export default meta | ||
|
||
type Story = StoryObj<typeof BulkImportButton> | ||
|
||
/** | ||
* 一括登録ボタン | ||
*/ | ||
export const Default: Story = { | ||
args: {}, | ||
} |
35 changes: 35 additions & 0 deletions
35
sample/src/components/organisms/products/bulk-import-button.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import StandardButton from '@/components/atoms/buttons/standard-button' | ||
import { parse } from '@/libs/papaparse' | ||
import { validationSchema } from '@/reducks/products/types' | ||
import React, { ChangeEvent, useCallback } from 'react' | ||
import { z } from 'zod' | ||
|
||
const BulkImportButton = React.memo(function BulkImportButton() { | ||
const inputRef = React.useRef<HTMLInputElement>(null) | ||
const onChange = useCallback(async (event: ChangeEvent<HTMLInputElement>) => { | ||
const file = event.target.files?.[0] | ||
if (!file) return | ||
|
||
const parsed = await parse(file, z.array(validationSchema)) | ||
alert(JSON.stringify(parsed)) | ||
}, []) | ||
|
||
const upload = useCallback(() => { | ||
inputRef.current?.click() | ||
}, []) | ||
|
||
return ( | ||
<div> | ||
<StandardButton onclick={upload} name="一括登録" /> | ||
<input | ||
hidden | ||
type="file" | ||
accept=".csv" | ||
ref={inputRef} | ||
onChange={onChange} | ||
/> | ||
</div> | ||
) | ||
}) | ||
|
||
export default BulkImportButton |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters