Merge branch 'dev' of https://git.hanasys.jp/qcast3/onsitesurvey into feature/survey
This commit is contained in:
commit
9185b5cb7a
@ -7,31 +7,10 @@ const nextConfig: NextConfig = {
|
|||||||
includePaths: [path.join(__dirname, './src/styles')],
|
includePaths: [path.join(__dirname, './src/styles')],
|
||||||
},
|
},
|
||||||
async rewrites() {
|
async rewrites() {
|
||||||
return [
|
|
||||||
{
|
|
||||||
source: '/:path*',
|
|
||||||
destination: `${process.env.NEXT_PUBLIC_API_URL}/:path*`,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
},
|
|
||||||
async headers() {
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
source: '/api/:path*',
|
source: '/api/:path*',
|
||||||
headers: [
|
destination: `${process.env.NEXT_PUBLIC_API_URL}/api/:path*`,
|
||||||
{
|
|
||||||
key: 'Access-Control-Allow-Origin',
|
|
||||||
value: '*',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: 'Access-Control-Allow-Methods',
|
|
||||||
value: 'GET, POST, PUT, DELETE, OPTIONS',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: 'Access-Control-Allow-Headers',
|
|
||||||
value: 'Content-Type, Authorization',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
@ -1,21 +0,0 @@
|
|||||||
'use server'
|
|
||||||
|
|
||||||
import { SessionData, sessionOptions } from '@/libs/session'
|
|
||||||
import { getIronSession } from 'iron-session'
|
|
||||||
import { cookies } from 'next/headers'
|
|
||||||
import { redirect } from 'next/navigation'
|
|
||||||
|
|
||||||
export const logout = async () => {
|
|
||||||
const cookieStore = await cookies()
|
|
||||||
const session = await getIronSession<SessionData>(cookieStore, sessionOptions)
|
|
||||||
|
|
||||||
session.destroy()
|
|
||||||
return redirect('/login')
|
|
||||||
}
|
|
||||||
|
|
||||||
export const getSession = async () => {
|
|
||||||
const cookieStore = await cookies()
|
|
||||||
const session = await getIronSession<SessionData>(cookieStore, sessionOptions)
|
|
||||||
|
|
||||||
return session
|
|
||||||
}
|
|
||||||
@ -120,4 +120,8 @@ export const surveySalesApi = {
|
|||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
update: async (data: SurveySalesBasicInfo): Promise<SurveySalesBasicInfo> => {
|
||||||
|
const response = await axiosInstance.put<SurveySalesBasicInfo>(`/api/survey-sales`, data)
|
||||||
|
return response.data
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,37 +0,0 @@
|
|||||||
import { axiosInstance } from '@/libs/axios'
|
|
||||||
|
|
||||||
export interface UserData {
|
|
||||||
username: string
|
|
||||||
email: string
|
|
||||||
password: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface User {
|
|
||||||
id: number
|
|
||||||
username: string
|
|
||||||
email: string
|
|
||||||
created_at: string
|
|
||||||
updated_at: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface LoginData {
|
|
||||||
username: string
|
|
||||||
password: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export const userApi = {
|
|
||||||
create: async (data: UserData): Promise<User> => {
|
|
||||||
const response = await axiosInstance.post<User>('/api/user/create', data)
|
|
||||||
return response.data
|
|
||||||
},
|
|
||||||
|
|
||||||
getList: async (): Promise<User[]> => {
|
|
||||||
const response = await axiosInstance.get<User[]>('/api/user/list')
|
|
||||||
return response.data
|
|
||||||
},
|
|
||||||
|
|
||||||
getUser: async (data: LoginData): Promise<User> => {
|
|
||||||
const response = await axiosInstance.post<User>(`/api/user`, data)
|
|
||||||
return response.data
|
|
||||||
},
|
|
||||||
}
|
|
||||||
@ -1,12 +0,0 @@
|
|||||||
import { NextResponse } from 'next/server'
|
|
||||||
import { prisma } from '@/libs/prisma'
|
|
||||||
|
|
||||||
export async function POST(request: Request) {
|
|
||||||
const body = await request.json()
|
|
||||||
// @ts-ignore
|
|
||||||
const suitables = await prisma.MS_SUITABLE.createMany({
|
|
||||||
data: body,
|
|
||||||
})
|
|
||||||
|
|
||||||
return NextResponse.json({ message: 'Suitable created successfully' })
|
|
||||||
}
|
|
||||||
@ -19,3 +19,25 @@ export async function GET() {
|
|||||||
console.error(error)
|
console.error(error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function GET(request: Request) {
|
||||||
|
// @ts-ignore
|
||||||
|
const res = await prisma.SD_SERVEY_SALES_BASIC_INFO.findMany({
|
||||||
|
include: {
|
||||||
|
detail_info: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
return NextResponse.json(res)
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function PUT(request: Request) {
|
||||||
|
const body = await request.json()
|
||||||
|
console.log('🚀 ~ PUT ~ body:', body)
|
||||||
|
const detailInfo = { ...body.detail_info, basic_info_id: body.id }
|
||||||
|
console.log('🚀 ~ PUT ~ detailInfo:', detailInfo)
|
||||||
|
// @ts-ignore
|
||||||
|
const res = await prisma.SD_SERVEY_SALES_DETAIL_INFO.create({
|
||||||
|
data: detailInfo,
|
||||||
|
})
|
||||||
|
return NextResponse.json({ message: 'Survey sales updated successfully' })
|
||||||
|
}
|
||||||
|
|||||||
@ -1,23 +0,0 @@
|
|||||||
import { NextResponse } from 'next/server'
|
|
||||||
import { prisma } from '@/libs/prisma'
|
|
||||||
|
|
||||||
export async function POST(request: Request) {
|
|
||||||
try {
|
|
||||||
const body = await request.json()
|
|
||||||
const { username, email, password } = body
|
|
||||||
|
|
||||||
const user = await prisma.user.create({
|
|
||||||
data: {
|
|
||||||
username,
|
|
||||||
email,
|
|
||||||
password,
|
|
||||||
updated_at: new Date(),
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
return NextResponse.json(user)
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error creating user:', error)
|
|
||||||
return NextResponse.json({ error: 'Error creating user' }, { status: 500 })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,7 +0,0 @@
|
|||||||
import { NextResponse } from 'next/server'
|
|
||||||
import { prisma } from '@/libs/prisma'
|
|
||||||
|
|
||||||
export const GET = async () => {
|
|
||||||
const users = await prisma.user.findMany()
|
|
||||||
return NextResponse.json(users)
|
|
||||||
}
|
|
||||||
@ -1,37 +0,0 @@
|
|||||||
import { NextResponse } from 'next/server'
|
|
||||||
import { prisma } from '@/libs/prisma'
|
|
||||||
import { getIronSession } from 'iron-session'
|
|
||||||
import { cookies } from 'next/headers'
|
|
||||||
import { SessionData, sessionOptions } from '@/libs/session'
|
|
||||||
|
|
||||||
export async function POST(request: Request) {
|
|
||||||
const { username, password } = await request.json()
|
|
||||||
|
|
||||||
console.log('🚀 ~ POST ~ username:', username)
|
|
||||||
console.log('🚀 ~ POST ~ password:', password)
|
|
||||||
|
|
||||||
const user = await prisma.user.findFirst({
|
|
||||||
where: {
|
|
||||||
username: username,
|
|
||||||
password: password,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
console.log('🚀 ~ POST ~ user:', user)
|
|
||||||
|
|
||||||
if (!user) {
|
|
||||||
return NextResponse.json({ error: 'User not found' }, { status: 404 })
|
|
||||||
}
|
|
||||||
|
|
||||||
const cookieStore = await cookies()
|
|
||||||
const session = await getIronSession<SessionData>(cookieStore, sessionOptions)
|
|
||||||
console.log('start session edit!')
|
|
||||||
session.username = user.username!
|
|
||||||
session.email = user.email!
|
|
||||||
session.isLoggedIn = true
|
|
||||||
console.log('end session edit!')
|
|
||||||
await session.save()
|
|
||||||
console.log('🚀 ~ POST ~ session:', session)
|
|
||||||
|
|
||||||
// return NextResponse.redirect(new URL(process.env.NEXT_PUBLIC_URL!, request.url))
|
|
||||||
return NextResponse.json(user)
|
|
||||||
}
|
|
||||||
@ -1,14 +0,0 @@
|
|||||||
import Counter from '@/components/Counter'
|
|
||||||
|
|
||||||
export default function page() {
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<div className="flex flex-col items-center p-4">
|
|
||||||
<h1 className="text-4xl font-bold">Counter</h1>
|
|
||||||
<div className="p-4">
|
|
||||||
<Counter />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@ -1,26 +0,0 @@
|
|||||||
@import "tailwindcss";
|
|
||||||
|
|
||||||
:root {
|
|
||||||
--background: #ffffff;
|
|
||||||
--foreground: #171717;
|
|
||||||
}
|
|
||||||
|
|
||||||
@theme inline {
|
|
||||||
--color-background: var(--background);
|
|
||||||
--color-foreground: var(--foreground);
|
|
||||||
--font-sans: var(--font-geist-sans);
|
|
||||||
--font-mono: var(--font-geist-mono);
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (prefers-color-scheme: dark) {
|
|
||||||
:root {
|
|
||||||
--background: #0a0a0a;
|
|
||||||
--foreground: #ededed;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
body {
|
|
||||||
background: var(--background);
|
|
||||||
color: var(--foreground);
|
|
||||||
font-family: Arial, Helvetica, sans-serif;
|
|
||||||
}
|
|
||||||
@ -1,18 +1,5 @@
|
|||||||
import type { Metadata } from 'next'
|
import type { Metadata } from 'next'
|
||||||
import ReactQueryProviders from '@/providers/ReactQueryProvider'
|
import ReactQueryProviders from '@/providers/ReactQueryProvider'
|
||||||
import { Geist, Geist_Mono } from 'next/font/google'
|
|
||||||
import Footer from '@/components/common/Footer'
|
|
||||||
import './globals.css'
|
|
||||||
|
|
||||||
const geistSans = Geist({
|
|
||||||
variable: '--font-geist-sans',
|
|
||||||
subsets: ['latin'],
|
|
||||||
})
|
|
||||||
|
|
||||||
const geistMono = Geist_Mono({
|
|
||||||
variable: '--font-geist-mono',
|
|
||||||
subsets: ['latin'],
|
|
||||||
})
|
|
||||||
|
|
||||||
export const metadata: Metadata = {
|
export const metadata: Metadata = {
|
||||||
title: 'Create Next App',
|
title: 'Create Next App',
|
||||||
@ -28,7 +15,6 @@ export default function RootLayout({
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
<body>
|
<body>
|
||||||
<ReactQueryProviders>{children}</ReactQueryProviders>
|
<ReactQueryProviders>{children}</ReactQueryProviders>
|
||||||
<Footer />
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
)
|
)
|
||||||
|
|||||||
@ -1,12 +0,0 @@
|
|||||||
import Login from '@/components/Login'
|
|
||||||
|
|
||||||
export default function page() {
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<div className="flex flex-col items-center justify-center h-screen">
|
|
||||||
<h1 className="text-2xl font-bold">Login</h1>
|
|
||||||
<Login />
|
|
||||||
</div>
|
|
||||||
</>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@ -1,44 +1,7 @@
|
|||||||
import Link from 'next/link'
|
|
||||||
import User from '@/components/User'
|
|
||||||
|
|
||||||
export default async function Home() {
|
export default async function Home() {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="flex flex-col items-center p-4">
|
<h1>퍼블 작업 대기중</h1>
|
||||||
<h1 className="text-4xl font-bold">Index</h1>
|
|
||||||
|
|
||||||
<div className="p-4">
|
|
||||||
<Link href="/counter">
|
|
||||||
<button className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">Zustand Counter Example</button>
|
|
||||||
</Link>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="p-4">
|
|
||||||
<Link href="/login">
|
|
||||||
<button className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">Session Login Example</button>
|
|
||||||
</Link>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="p-4">
|
|
||||||
<Link href="/suitable">
|
|
||||||
<button className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">적합성 예제</button>
|
|
||||||
</Link>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="p-4">
|
|
||||||
<Link href="/pdf-download">
|
|
||||||
<button className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">PDF 다운로드</button>
|
|
||||||
</Link>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="p-4">
|
|
||||||
<Link href="/survey-sales">
|
|
||||||
<button className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">조사 매물</button>
|
|
||||||
</Link>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<User />
|
|
||||||
</div>
|
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,10 +0,0 @@
|
|||||||
import PdfDownloadNew from '@/components/PdfDownloadNew'
|
|
||||||
|
|
||||||
export default function page() {
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<h1 className="text-2xl font-bold">PDF 다운로드</h1>
|
|
||||||
<PdfDownloadNew />
|
|
||||||
</>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@ -1,11 +0,0 @@
|
|||||||
import SuitableDetails from '@/components/SuitableDetails'
|
|
||||||
|
|
||||||
export default async function page({ params }: { params: Promise<{ slug: string }> }) {
|
|
||||||
const { slug } = await params
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<h1>Suitable Details</h1>
|
|
||||||
<SuitableDetails roofMaterial={slug} />
|
|
||||||
</>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@ -1,13 +0,0 @@
|
|||||||
import Suitable from '@/components/Suitable'
|
|
||||||
import SuitableSearch from '@/components/SuitableSearch'
|
|
||||||
|
|
||||||
export default function suitablePage() {
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<SuitableSearch />
|
|
||||||
<Suitable />
|
|
||||||
{/* 최초 한번 밀어넣음 */}
|
|
||||||
{/* <SuitableCreateBtn /> */}
|
|
||||||
</>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@ -1,31 +0,0 @@
|
|||||||
'use client'
|
|
||||||
|
|
||||||
import { useCountStore } from '@/store/counter'
|
|
||||||
|
|
||||||
export default function Counter() {
|
|
||||||
const { count, increment, decrement, paramSetting, resetCount } = useCountStore()
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="flex gap-2 items-center justify-center flex-col">
|
|
||||||
<div className="text-2xl">{count}</div>
|
|
||||||
<div className="flex gap-2">
|
|
||||||
<button className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded" onClick={decrement}>
|
|
||||||
-
|
|
||||||
</button>
|
|
||||||
<button className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded" onClick={increment}>
|
|
||||||
+
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<div className="flex">
|
|
||||||
<button className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded" onClick={() => paramSetting({ count: 500 })}>
|
|
||||||
임의 숫자
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<div className="flex">
|
|
||||||
<button className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded" onClick={resetCount}>
|
|
||||||
리셋
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@ -1,79 +0,0 @@
|
|||||||
'use client'
|
|
||||||
|
|
||||||
import { userApi } from '@/api/user'
|
|
||||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
|
||||||
import { AxiosError } from 'axios'
|
|
||||||
import { useRouter } from 'next/navigation'
|
|
||||||
import { useState } from 'react'
|
|
||||||
|
|
||||||
export default function Login() {
|
|
||||||
const [username, setUsername] = useState('')
|
|
||||||
const [password, setPassword] = useState('')
|
|
||||||
const [isLogin, setIsLogin] = useState(false)
|
|
||||||
const router = useRouter()
|
|
||||||
|
|
||||||
const { data, error, isPending } = useQuery({
|
|
||||||
queryKey: ['login-user'],
|
|
||||||
queryFn: async () => {
|
|
||||||
try {
|
|
||||||
const result = await userApi.getUser({ username, password })
|
|
||||||
router.push('/')
|
|
||||||
return result
|
|
||||||
} catch (error: unknown) {
|
|
||||||
if (error instanceof AxiosError) {
|
|
||||||
console.log('🚀 ~ handleLogin ~ error:', error.response?.data?.error)
|
|
||||||
setUsername('')
|
|
||||||
setPassword('')
|
|
||||||
setIsLogin(false)
|
|
||||||
}
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
},
|
|
||||||
enabled: isLogin,
|
|
||||||
retry: false,
|
|
||||||
staleTime: 0,
|
|
||||||
})
|
|
||||||
|
|
||||||
const handleLogin = async () => {
|
|
||||||
console.log('🚀 ~ Login ~ username:', username)
|
|
||||||
console.log('🚀 ~ Login ~ password:', password)
|
|
||||||
|
|
||||||
setIsLogin(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
const queryClient = useQueryClient()
|
|
||||||
const { mutate: createUser } = useMutation({
|
|
||||||
mutationFn: userApi.create,
|
|
||||||
onSuccess: () => {
|
|
||||||
queryClient.invalidateQueries({ queryKey: ['user-list'] })
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<div className="w-full max-w-sm min-w-[200px] m-4">
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
className="w-full bg-transparent placeholder:text-slate-400 text-slate-700 text-sm border border-slate-200 rounded-md px-3 py-2 transition duration-300 ease focus:outline-none focus:border-slate-400 hover:border-slate-300 shadow-sm focus:shadow"
|
|
||||||
placeholder="Username"
|
|
||||||
name="username"
|
|
||||||
value={username}
|
|
||||||
onChange={(e) => setUsername(e.target.value)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div className="w-full max-w-sm min-w-[200px] m-4">
|
|
||||||
<input
|
|
||||||
type="password"
|
|
||||||
className="w-full bg-transparent placeholder:text-slate-400 text-slate-700 text-sm border border-slate-200 rounded-md px-3 py-2 transition duration-300 ease focus:outline-none focus:border-slate-400 hover:border-slate-300 shadow-sm focus:shadow"
|
|
||||||
placeholder="Password"
|
|
||||||
name="password"
|
|
||||||
value={password}
|
|
||||||
onChange={(e) => setPassword(e.target.value)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<button className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded" onClick={handleLogin}>
|
|
||||||
Login
|
|
||||||
</button>
|
|
||||||
</>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@ -1,20 +0,0 @@
|
|||||||
'use client'
|
|
||||||
|
|
||||||
import { useRef } from 'react'
|
|
||||||
import generatePDF, { usePDF } from 'react-to-pdf'
|
|
||||||
|
|
||||||
export default function PdfDownloadNew() {
|
|
||||||
const { toPDF, targetRef } = usePDF({ filename: 'page.pdf' })
|
|
||||||
const myTargetRef = useRef(null)
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<button onClick={() => toPDF()}>Download PDF</button>
|
|
||||||
<div ref={targetRef}>Content to be generated to PDF</div>
|
|
||||||
<button onClick={() => generatePDF(myTargetRef, { filename: 'mypage.pdf' })}>Download PDF</button>
|
|
||||||
<div ref={myTargetRef}>
|
|
||||||
<h1>Hello</h1>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@ -1,29 +0,0 @@
|
|||||||
'use client'
|
|
||||||
|
|
||||||
import { suitableApi } from '@/api/suitable'
|
|
||||||
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
|
||||||
|
|
||||||
export default function SuitableCreateBtn() {
|
|
||||||
const queryClient = useQueryClient()
|
|
||||||
|
|
||||||
const {
|
|
||||||
mutate: createSuitable,
|
|
||||||
isPending,
|
|
||||||
error,
|
|
||||||
} = useMutation({
|
|
||||||
mutationFn: suitableApi.create,
|
|
||||||
onSuccess: () => {
|
|
||||||
queryClient.invalidateQueries({ queryKey: ['suitable-list'] })
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<div>
|
|
||||||
<button className="bg-blue-500 text-white px-4 py-2 rounded-md" onClick={() => createSuitable()}>
|
|
||||||
suitable create!!
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@ -1,15 +1,18 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { suitableApi } from '@/api/suitable'
|
import { Suitable, suitableApi } from '@/api/suitable'
|
||||||
import { useQuery } from '@tanstack/react-query'
|
import { useQuery, useQueryClient } from '@tanstack/react-query'
|
||||||
|
|
||||||
export default function SuitableDetails({ roofMaterial }: { roofMaterial: string }) {
|
export default function SuitableDetails({ roofMaterial }: { roofMaterial: string }) {
|
||||||
console.log('🚀 ~ SuitableDetails ~ roofMaterial:', roofMaterial)
|
console.log('🚀 ~ SuitableDetails ~ roofMaterial:', roofMaterial)
|
||||||
const { data, error, isPending } = useQuery({
|
// const { data, error, isPending } = useQuery({
|
||||||
queryKey: ['suitable-details'],
|
// queryKey: ['suitable-details'],
|
||||||
queryFn: () => suitableApi.getDetails(roofMaterial),
|
// queryFn: () => suitableApi.getDetails(roofMaterial),
|
||||||
staleTime: 0,
|
// staleTime: 0,
|
||||||
})
|
// })
|
||||||
|
const cache = useQueryClient()
|
||||||
|
const listData = cache.getQueryData(['suitable-list']) as Suitable[]
|
||||||
|
const data = listData.filter((item) => item.roof_material === roofMaterial)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@ -1,9 +1,12 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { surveySalesApi, SurveySalesBasicInfo } from '@/api/surveySales'
|
import { surveySalesApi, SurveySalesBasicInfo, SurveySalesDetailInfo } from '@/api/surveySales'
|
||||||
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||||
|
import { useState } from 'react'
|
||||||
|
|
||||||
export default function SurveySales() {
|
export default function SurveySales() {
|
||||||
|
const [isSearch, setIsSearch] = useState(false)
|
||||||
|
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
|
|
||||||
const {
|
const {
|
||||||
@ -34,6 +37,68 @@ export default function SurveySales() {
|
|||||||
createSurveySales(data)
|
createSurveySales(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { data, error: errorList } = useQuery({
|
||||||
|
queryKey: ['survey-sales', 'list'],
|
||||||
|
queryFn: surveySalesApi.getList,
|
||||||
|
enabled: isSearch,
|
||||||
|
})
|
||||||
|
|
||||||
|
const { mutate: updateSurveySales } = useMutation({
|
||||||
|
mutationFn: surveySalesApi.update,
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: ['survey-sales', 'list'] })
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const handleUpdateSurveySales = () => {
|
||||||
|
const detailData: SurveySalesDetailInfo = {
|
||||||
|
contract_capacity: '1100',
|
||||||
|
retail_company: 'test company',
|
||||||
|
supplementary_facilities: 1,
|
||||||
|
supplementary_facilities_etc: '',
|
||||||
|
installation_system: 3,
|
||||||
|
installation_system_etc: '',
|
||||||
|
construction_year: 4,
|
||||||
|
construction_year_etc: '',
|
||||||
|
roof_material: 1,
|
||||||
|
roof_material_etc: '',
|
||||||
|
roof_shape: 2,
|
||||||
|
roof_shape_etc: '',
|
||||||
|
roof_slope: '4.5',
|
||||||
|
house_structure: 1,
|
||||||
|
house_structure_etc: '',
|
||||||
|
rafter_material: 5,
|
||||||
|
rafter_material_etc: 'test message',
|
||||||
|
rafter_size: 3,
|
||||||
|
rafter_size_etc: '',
|
||||||
|
rafter_pitch: 2,
|
||||||
|
rafter_pitch_etc: '',
|
||||||
|
rafter_direction: 3,
|
||||||
|
open_field_plate_kind: 3,
|
||||||
|
open_field_plate_kind_etc: '',
|
||||||
|
open_field_plate_thickness: '',
|
||||||
|
leak_trace: false,
|
||||||
|
waterproof_material: 2,
|
||||||
|
waterproof_material_etc: '',
|
||||||
|
insulation_presence: 3,
|
||||||
|
insulation_presence_etc: '',
|
||||||
|
structure_order: 2,
|
||||||
|
structure_order_etc: '',
|
||||||
|
installation_availability: 1,
|
||||||
|
installation_availability_etc: '',
|
||||||
|
memo: 'test memo',
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!data) return
|
||||||
|
|
||||||
|
const surveySalesData: SurveySalesBasicInfo = {
|
||||||
|
...data[0],
|
||||||
|
detail_info: { ...detailData },
|
||||||
|
}
|
||||||
|
|
||||||
|
updateSurveySales(surveySalesData)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="flex items-center justify-center">
|
<div className="flex items-center justify-center">
|
||||||
@ -41,13 +106,22 @@ export default function SurveySales() {
|
|||||||
<button className="bg-blue-500 text-white px-4 py-2 rounded-md" onClick={handleSurveySales}>
|
<button className="bg-blue-500 text-white px-4 py-2 rounded-md" onClick={handleSurveySales}>
|
||||||
신규 등록
|
신규 등록
|
||||||
</button>
|
</button>
|
||||||
<button className="bg-blue-500 text-white px-4 py-2 rounded-md">조회</button>
|
<button className="bg-blue-500 text-white px-4 py-2 rounded-md" onClick={() => setIsSearch(true)}>
|
||||||
|
조회
|
||||||
|
</button>
|
||||||
|
<button className="bg-blue-500 text-white px-4 py-2 rounded-md" onClick={handleUpdateSurveySales}>
|
||||||
|
수정 (detail info add)
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{/* <div className="bg-orange-100 border-l-4 border-orange-500 text-orange-700 p-4 m-4" role="alert">
|
{/* <div className="bg-orange-100 border-l-4 border-orange-500 text-orange-700 p-4 m-4" role="alert">
|
||||||
<p className="font-bold">Be Warned</p>
|
<p className="font-bold">Be Warned</p>
|
||||||
<p>기본 데이터 세팅 되어있습니다.</p>
|
<p>기본 데이터 세팅 되어있습니다.</p>
|
||||||
</div> */}
|
</div> */}
|
||||||
|
<div>
|
||||||
|
{errorList && <div>Error: {errorList.message}</div>}
|
||||||
|
{data && data.map((item) => <div key={item.id}>{JSON.stringify(item)}</div>)}
|
||||||
|
</div>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,52 +0,0 @@
|
|||||||
'use client'
|
|
||||||
|
|
||||||
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
|
||||||
import { userApi } from '@/api/user'
|
|
||||||
import { logout } from '@/api/auth'
|
|
||||||
import UserList from '@/components/UserList'
|
|
||||||
|
|
||||||
export default function User() {
|
|
||||||
const queryClient = useQueryClient()
|
|
||||||
|
|
||||||
const {
|
|
||||||
mutate: createUser,
|
|
||||||
isPending,
|
|
||||||
error,
|
|
||||||
} = useMutation({
|
|
||||||
mutationFn: userApi.create,
|
|
||||||
onSuccess: () => {
|
|
||||||
queryClient.invalidateQueries({ queryKey: ['user-list'] })
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<div className="p-4">
|
|
||||||
<button
|
|
||||||
className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded"
|
|
||||||
onClick={() => createUser({ username: 'user1', email: 'user1@example.com', password: 'password1' })}
|
|
||||||
>
|
|
||||||
User Create1
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<div className="p-4">
|
|
||||||
<button
|
|
||||||
className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded"
|
|
||||||
onClick={() => createUser({ username: 'user2', email: 'user2@example.com', password: 'password2' })}
|
|
||||||
>
|
|
||||||
User Create2
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<div className="p-4">
|
|
||||||
{error && <div>Error: {error.message}</div>}
|
|
||||||
{isPending ? <div>Loading...</div> : <UserList />}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="p-4">
|
|
||||||
<button className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded" onClick={logout}>
|
|
||||||
Logout
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@ -1,25 +0,0 @@
|
|||||||
'use client'
|
|
||||||
|
|
||||||
import { useQuery } from '@tanstack/react-query'
|
|
||||||
import { userApi, User } from '@/api/user'
|
|
||||||
|
|
||||||
export default function UserList() {
|
|
||||||
const { data, error, isPending } = useQuery({
|
|
||||||
queryKey: ['user-list'],
|
|
||||||
queryFn: userApi.getList,
|
|
||||||
})
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
{isPending && <div>Loading...</div>}
|
|
||||||
{error && <div>Error: {error.message}</div>}
|
|
||||||
{data && (
|
|
||||||
<div>
|
|
||||||
{data.map((user: User) => (
|
|
||||||
<div key={user.id}>{user.username}</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@ -1,13 +0,0 @@
|
|||||||
import Link from 'next/link'
|
|
||||||
|
|
||||||
export default function Footer() {
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<div className="p-4">
|
|
||||||
<Link href="/">
|
|
||||||
<button className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">HOME</button>
|
|
||||||
</Link>
|
|
||||||
</div>
|
|
||||||
</>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user