-
Notifications
You must be signed in to change notification settings - Fork 1
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
swrとorval導入 #902
base: develop
Are you sure you want to change the base?
swrとorval導入 #902
Conversation
マージ先feat/kubosaka/create-budgets-openapiなのは意図ありです? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
よさそう!
型アサシエーションとかの部分多分直せました
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.eslintrc.json
"ignorePatterns": ["orval.config.js", "src/generated/"]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
自動生成系はlint無視してもよさそう。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
これでyearPeriodsと型の修正。全コード貼り付け
微修正はよろしくお願いします。
import clsx from 'clsx';
import type { NextPage } from 'next';
import Head from 'next/head';
import { useState } from 'react';
import OpenDeleteModalButton from '@/components/sponsors/OpenDeleteModalButton';
import OpenEditModalButton from '@/components/sponsors/OpenEditModalButton';
import { useGetSponsorsPeriodsYear, useGetYearsPeriods } from '@/generated/hooks';
import { Card, Loading, Title } from '@components/common';
import MainLayout from '@components/layout/MainLayout';
import OpenAddModalButton from '@components/sponsors/OpenAddModalButton';
const date = new Date();
const Sponsorship: NextPage = () => {
const { data: getYearPeriods } = useGetYearsPeriods();
const yearPeriods = getYearPeriods?.data;
const [selectedYear, setSelectedYear] = useState<string>(
yearPeriods ? String(yearPeriods[yearPeriods.length - 1].year) : String(date.getFullYear()),
);
const { data, isLoading, error } = useGetSponsorsPeriodsYear(Number(selectedYear));
const sponsors = data?.data;
if (isLoading) return <Loading />;
if (error) return <div>error...</div>;
return (
<MainLayout>
<Head>
<title>協賛企業一覧</title>
<meta name='viewport' content='initial-scale=1.0, width=device-width' />
</Head>
<Card w='w-1/1'>
<div className='mx-5 mt-10'>
<div className='flex'>
<Title title={'協賛企業一覧'} />
<select
className='w-100'
defaultValue={selectedYear}
onChange={(e) => setSelectedYear(e.target.value)}
>
{yearPeriods &&
yearPeriods.map((year, index) => {
return (
<option value={year.year} key={index}>
{year.year}年度
</option>
);
})}
</select>
</div>
<div className='hidden justify-end md:flex'>
<OpenAddModalButton>協賛企業登録</OpenAddModalButton>
</div>
</div>
<div className='mb-2 overflow-scroll p-5'>
<table className='mb-5 w-max table-auto border-collapse md:w-full md:table-fixed'>
<thead>
<tr className='border border-x-white-0 border-b-primary-1 border-t-white-0 py-3'>
<th className='w-1/8 border-b-primary-1 pb-2'>
<div className='mr-1 text-center text-sm text-black-600'>企業名</div>
</th>
<th className='w-1/8 border-b-primary-1 pb-2'>
<div className='text-center text-sm text-black-600'>電話番号</div>
</th>
<th className='w-1/6 border-b-primary-1 pb-2'>
<div className='text-center text-sm text-black-600'>メール</div>
</th>
<th className='w-1/6 border-b-primary-1 pb-2'>
<div className='text-center'>住所</div>
</th>
<th className='w-1/8 border-b-primary-1 pb-2'>
<div className='text-center text-black-600'>代表者</div>
</th>
<th className='w-1/12 border-b-primary-1 pb-2'>
<div className='text-center text-black-600'></div>
</th>
</tr>
</thead>
<tbody className='border border-x-white-0 border-b-primary-1 border-t-white-0'>
{sponsors && sponsors.length > 0 ? (
sponsors.map((sponsor, index) => (
<tr
className={clsx(index !== sponsors.length - 1 && 'border-b')}
key={sponsor.id}
>
<td className='py-3'>
<div className='text-center text-black-300'>{sponsor.name}</div>
</td>
<td>
<div className='text-center text-black-300'>{sponsor.tel}</div>
</td>
<td>
<div className='text-center text-black-300'>{sponsor.email}</div>
</td>
<td>
<div className='text-center text-black-300'>{sponsor.address}</div>
</td>
<td>
<div className='text-center text-black-300'>{sponsor.representative}</div>
</td>
<td>
<div className='flex gap-3'>
<OpenEditModalButton sponsor={sponsor} />
<OpenDeleteModalButton id={sponsor.id || 0} />
</div>
</td>
</tr>
))
) : (
<tr>
<td colSpan={6} className='py-3'>
<div className='text-center text-black-300'>データがありません</div>
</td>
</tr>
)}
</tbody>
</table>
</div>
</Card>
<div className='fixed bottom-4 right-4 md:hidden'>
<OpenAddModalButton />
</div>
</MainLayout>
);
};
export default Sponsorship;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getのcontentに型付けました。
components/sponsorにid追加しました。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
teacherのコメントアウトは何も弄ってません
あとtsconfig.paths.jsonにこれも追加してもいいかも! |
openapiの定義からブランチ切ったためですね |
概要
make gen-front-api
でhooksとTypeを自動生成しますapiクライアントにはswr+fetchを使用しました。
swrはvercelが提供しており、軽量でシンプルなので採用しました。
画面スクリーンショット等
URL
スクリーンショット
テスト項目
備考