Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
proxy-manager-frontend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
aolda
proxy-manager-frontend
Commits
7adf0000
Commit
7adf0000
authored
2 months ago
by
한동현
Browse files
Options
Downloads
Patches
Plain Diff
feat: 포트포워딩 등록 페이지 API 연동
parent
7c7a966a
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/pages/forwarding/Create.tsx
+43
-10
43 additions, 10 deletions
src/pages/forwarding/Create.tsx
with
43 additions
and
10 deletions
src/pages/forwarding/Create.tsx
+
43
−
10
View file @
7adf0000
import
{
z
}
from
'
zod
'
;
import
{
zodResolver
}
from
'
@hookform/resolvers/zod
'
;
import
{
Link
}
from
'
react-router
'
;
import
{
Link
,
useNavigate
}
from
'
react-router
'
;
import
{
useForm
}
from
'
react-hook-form
'
;
import
{
Button
}
from
'
@/components/ui/button
'
;
import
{
Card
,
CardContent
,
CardHeader
,
CardTitle
}
from
'
@/components/ui/card
'
;
import
{
Input
}
from
'
@/components/ui/input
'
;
import
{
toast
}
from
'
sonner
'
;
import
{
Form
,
FormControl
,
FormDescription
,
FormField
,
FormItem
,
FormLabel
,
FormMessage
}
from
'
@/components/ui/form
'
;
import
{
useAuthStore
}
from
'
@/stores/authStore
'
;
const
formSchema
=
z
.
object
({
name
:
z
.
string
({
required_error
:
'
서버 이름을 입력해주세요
'
}).
min
(
1
,
{
message
:
'
서버 이름을 입력해주세요
'
}),
p
ort
:
z
serverP
ort
:
z
.
number
({
required_error
:
'
도메인 주소를 입력해주세요
'
})
.
min
(
20000
,
{
message
:
'
포트 번호는 20000 이상이어야 합니다
'
})
.
max
(
29999
,
{
message
:
'
포트 번호는 29999 이하여야 합니다
'
}),
instance
_i
p
:
z
instance
I
p
:
z
.
string
({
required_error
:
'
인스턴스 IP를 입력해주세요
'
})
.
regex
(
/^
((
25
[
0-5
]
|
(
2
[
0-4
]
|1
\d
|
[
1-9
]
|
)\d)\.?\b){4}
$/
,
{
message
:
'
올바른 IP 주소를 입력해주세요
'
,
...
...
@@ -23,18 +24,50 @@ const formSchema = z.object({
});
export
default
function
ForwardingCreate
()
{
const
navigate
=
useNavigate
();
const
{
selectedProject
}
=
useAuthStore
();
const
form
=
useForm
<
z
.
infer
<
typeof
formSchema
>>
({
resolver
:
zodResolver
(
formSchema
),
defaultValues
:
{
name
:
''
,
p
ort
:
undefined
,
instance
_i
p
:
''
,
serverP
ort
:
undefined
,
instance
I
p
:
''
,
},
});
function
onSubmit
(
values
:
z
.
infer
<
typeof
formSchema
>
)
{
console
.
log
(
'
제출된 데이터:
'
,
values
);
toast
.
warning
(
'
포트포워딩 설정을 등록합니다
'
);
async
function
onSubmit
(
values
:
z
.
infer
<
typeof
formSchema
>
)
{
const
{
name
,
serverPort
,
instanceIp
}
=
values
;
const
response
=
await
fetch
(
`/api/forwarding?projectId=
${
selectedProject
?.
id
}
`
,
{
method
:
'
POST
'
,
headers
:
{
'
Content-Type
'
:
'
application/json
'
,
},
body
:
JSON
.
stringify
({
name
,
serverPort
,
instanceIp
,
instancePort
:
22
,
}),
});
if
(
!
response
.
ok
)
{
console
.
error
(
response
);
const
{
code
}
=
await
response
.
json
();
if
(
code
==
'
DUPLICATED_INSTANCE_INFO
'
)
{
form
.
setError
(
'
instanceIp
'
,
{
type
:
'
custom
'
});
toast
.
error
(
'
이미 존재하는 포트포워딩 설정입니다
'
);
}
else
if
(
code
==
'
DUPLICATED_SERVER_PORT
'
)
{
form
.
setError
(
'
serverPort
'
,
{
type
:
'
custom
'
});
toast
.
error
(
'
이미 사용 중인 포트 번호입니다
'
);
}
else
{
toast
.
error
(
'
포트포워딩 설정 등록에 실패했습니다
'
);
}
}
else
{
toast
.
success
(
'
포트포워딩 설정이 등록되었습니다
'
);
navigate
(
'
/forwarding
'
);
}
}
return
(
...
...
@@ -68,7 +101,7 @@ export default function ForwardingCreate() {
<
FormField
control
=
{
form
.
control
}
name
=
"
p
ort"
name
=
"
serverP
ort"
render
=
{
({
field
})
=>
(
<
FormItem
>
<
FormLabel
required
>
포트 번호
</
FormLabel
>
...
...
@@ -90,7 +123,7 @@ export default function ForwardingCreate() {
<
FormField
control
=
{
form
.
control
}
name
=
"instance
_i
p"
name
=
"instance
I
p"
render
=
{
({
field
})
=>
(
<
FormItem
>
<
FormLabel
required
>
인스턴스 IP
</
FormLabel
>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment