Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions app/(dashboard)/my/_api/add-strategy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import axiosInstance from '@/shared/api/axios'

export interface StockTypeModel {
stockTypeId: number
stockTypeName: string
stockIconUrl: string
}

export interface TradeTypeModel {
tradeTypeId: number
tradeTypeName: string
tradeTypeIconUrl: string
}

export interface StrategyTypeResponseModel {
isSuccess: boolean
message: string
result: {
stockTypes: StockTypeModel[]
tradeTypes: TradeTypeModel[]
}
}

export type OperationCycleType = 'DAY' | 'POSITION'

export type MinimumInvestmentAmountType =
| 'UNDER_10K'
| 'UP_TO_500K'
| 'UP_TO_1M'
| 'UP_TO_2M'
| 'UP_TO_5M'
| 'FROM_5M_TO_10M'
| 'FROM_10M_TO_20M'
| 'FROM_20M_TO_30M'
| 'FROM_30M_TO_40M'
| 'FROM_40M_TO_50M'
| 'FROM_50M_TO_100M'
| 'ABOVE_100M'

export interface ProposalFileInfoModel {
proposalFileName: string
proposalFileSize: number
}

export interface StrategyModel {
strategyName: string
tradeTypeId: number
operationCycle: OperationCycleType
stockTypeIds: number[]
minimumInvestmentAmount: MinimumInvestmentAmountType
description: string
proposalFile?: ProposalFileInfoModel
}

export interface StrategyResponseModel {
isSuccess: boolean
message: string
result: {
presignedUrl: string
}
code: number
}

export const strategyApi = {
getStrategyTypes: () =>
axiosInstance.get<StrategyTypeResponseModel>('/api/my-strategies/register'),

registerStrategy: (data: StrategyModel) =>
axiosInstance.post<StrategyResponseModel>('/api/my-strategies/register', data),
}
33 changes: 33 additions & 0 deletions app/(dashboard)/my/_constants/investment-amount.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { MinimumInvestmentAmountType, OperationCycleType } from '../_api/add-strategy'

const INVESTMENT_AMOUNT_MAP: Record<MinimumInvestmentAmountType, string> = {
UNDER_10K: '1만원 ~ 500만원',
UP_TO_500K: '500만원',
UP_TO_1M: '1000만원',
UP_TO_2M: '2000만원',
UP_TO_5M: '5000만원',
FROM_5M_TO_10M: '5000만원 ~ 1억',
FROM_10M_TO_20M: '1억 ~ 2억',
FROM_20M_TO_30M: '2억 ~ 3억',
FROM_30M_TO_40M: '3억 ~ 4억',
FROM_40M_TO_50M: '4억 ~ 5억',
FROM_50M_TO_100M: '5억 ~ 10억',
ABOVE_100M: '10억 이상',
}

const OPERATION_CYCLE_MAP: Record<OperationCycleType, string> = {
DAY: '데이',
POSITION: '포지션',
}

export const minimumInvestmentAmountOptions = Object.entries(INVESTMENT_AMOUNT_MAP).map(
([value, label]) => ({
value,
label,
})
)

export const operationCycleOptions = Object.entries(OPERATION_CYCLE_MAP).map(([value, label]) => ({
value,
label,
}))
59 changes: 59 additions & 0 deletions app/(dashboard)/my/_hooks/query/use-add-strategy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { useState } from 'react'

import { useRouter } from 'next/navigation'

import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
import { AxiosError } from 'axios'

import {
StrategyModel,
StrategyResponseModel,
StrategyTypeResponseModel,
strategyApi,
} from '../../_api/add-strategy'

interface ErrorResponseModel {
message: string
}

export const useAddStrategy = () => {
const router = useRouter()
const queryClient = useQueryClient()
const [error, setError] = useState<string | null>(null)

const { data: strategyTypes, isLoading: isTypesLoading } = useQuery<
StrategyTypeResponseModel,
AxiosError<ErrorResponseModel>
>({
queryKey: ['strategyTypes'],
queryFn: () => strategyApi.getStrategyTypes().then((response) => response.data),
retry: false,
refetchOnWindowFocus: false,
})

const mutation = useMutation<
StrategyResponseModel,
AxiosError<ErrorResponseModel>,
StrategyModel
>({
mutationFn: (data) => strategyApi.registerStrategy(data).then((response) => response.data),
onSuccess: () => {
queryClient.invalidateQueries({
queryKey: ['addStrategies'],
})
router.back()
},
onError: (err) => {
const errorMessage = err.response?.data?.message || '전략 등록에 실패했습니다.'
setError(errorMessage)
},
})

return {
strategyTypes: strategyTypes?.result,
isTypesLoading,
registerStrategy: mutation.mutate,
isRegistering: mutation.isPending,
error,
}
}
Loading