Skip to content

Commit

Permalink
feature: Certificate details and creation
Browse files Browse the repository at this point in the history
  • Loading branch information
dogukanoksuz committed Aug 4, 2023
1 parent 909b038 commit 6ea5879
Show file tree
Hide file tree
Showing 7 changed files with 259 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/components/navigation/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function Sidebar({ className }: { className?: string }) {
return (
<div
className={cn(
"fixed z-30 w-full shrink-0 overflow-y-auto bg-background md:sticky md:block",
"fixed z-30 w-full shrink-0 overflow-y-auto bg-background md:sticky md:block print:hidden",
sidebarCtx[SIDEBARCTX_STATES.collapsed] && "hidden border-r"
)}
>
Expand Down
2 changes: 1 addition & 1 deletion src/components/navigation/site-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function SiteHeader() {
const sidebarCtx = useSidebarContext()

return (
<header className="top-0 z-40 w-full border-b bg-background">
<header className="top-0 z-40 w-full border-b bg-background print:hidden">
<div className="flex h-16 items-center space-x-4 px-6 sm:justify-between sm:space-x-0">
<div className="flex">
<div className="md:hidden">
Expand Down
79 changes: 75 additions & 4 deletions src/pages/settings/advanced/certificates/[id]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,100 @@ import { useEffect, useState } from "react"
import { useRouter } from "next/router"
import { apiService } from "@/services"

import { ICertificate } from "@/types/certificate"
import { ICertificateDetails } from "@/types/certificate"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
import PageHeader from "@/components/ui/page-header"
import { useToast } from "@/components/ui/use-toast"

export default function CertificateInformation() {
const router = useRouter()
const { toast } = useToast()

const [loading, setLoading] = useState<boolean>(true)
const [data, setData] = useState<ICertificate>()
const [data, setData] = useState<ICertificateDetails>()

useEffect(() => {
if (!router.query.id) return

apiService
.getInstance()
.get<ICertificate>(
.get<ICertificateDetails>(
`/settings/advanced/certificates/${router.query.id}/information`
)
.then((res) => {
setData(res.data)
})
.catch(() => {
toast({
title: "Hata",
description: "Sertifika detayları getirilirken bir hata oluştu.",
variant: "destructive",
})
})
.finally(() => {
setLoading(false)
})
}, [router.query.id])

return <>{JSON.stringify(data)}</>
return (
<>
<PageHeader
title="Sertifika Detayları"
description="Seçtiğiniz sertifikaya ait detaylı bilgileri görüntüleyebilirsiniz."
/>

<div className="p-8 pt-0">
<div className="grid grid-cols-2 gap-6">
<div className="space-y-2">
<h2 className="border-b w-full font-semibold text-lg mb-3">
İstemci Detayları
</h2>
<Label>IP Adresi</Label>
<Input value={data?.ip_address} disabled />
</div>
<div className="space-y-2 pt-[40px]">
<Label>Port</Label>
<Input value={data?.port} disabled />
</div>

<div className="space-y-2">
<h2 className="border-b w-full font-semibold text-lg mb-3">
Geçerlilik Süresi
</h2>
<Label>Başlangıç</Label>
<Input value={data?.valid_from} disabled />
</div>

<div className="space-y-2 pt-[40px]">
<Label>Bitiş</Label>
<Input value={data?.valid_to} disabled />
</div>

<div className="space-y-2">
<h2 className="border-b w-full font-semibold text-lg mb-3">
Genel Detaylar
</h2>
<Label>İstemci</Label>
<Input value={data?.issuer_cn} disabled />
</div>

<div className="space-y-2 pt-[40px]">
<Label>Otorite</Label>
<Input value={data?.issuer_dc} disabled />
</div>

<div className="space-y-2">
<Label>İstemci Parmak İzi</Label>
<Input value={data?.subject_key_identifier} disabled />
</div>

<div className="space-y-2">
<Label>Otorite Parmak İzi</Label>
<Input value={data?.authority_key_identifier} disabled />
</div>
</div>
</div>
</>
)
}
19 changes: 18 additions & 1 deletion src/pages/settings/advanced/certificates/index.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import { ReactElement, useEffect, useState } from "react"
import { useRouter } from "next/router"
import { NextPageWithLayout } from "@/pages/_app"
import { apiService } from "@/services"
import { PlusCircle } from "lucide-react"

import { ICertificate } from "@/types/certificate"
import { DivergentColumn } from "@/types/table"
import { useEmitter } from "@/hooks/useEmitter"
import { Button } from "@/components/ui/button"
import DataTable from "@/components/ui/data-table/data-table"
import { DataTableColumnHeader } from "@/components/ui/data-table/data-table-column-header"
import PageHeader from "@/components/ui/page-header"
import AdvancedLayout from "@/components/_layout/advanced_layout"
import { CertificateActions } from "@/components/settings/certificate-actions"

const AdvancedCertificateSettingsPage: NextPageWithLayout = () => {
const router = useRouter()

const [loading, setLoading] = useState<boolean>(true)
const [data, setData] = useState<ICertificate[]>([])

Expand Down Expand Up @@ -95,7 +100,19 @@ const AdvancedCertificateSettingsPage: NextPageWithLayout = () => {
data={data}
loading={loading}
selectable={false}
></DataTable>
>
<Button
variant="outline"
size="sm"
className="ml-auto h-8 lg:flex"
onClick={() =>
router.push("/settings/advanced/certificates/retrieve")
}
>
<PlusCircle className="mr-2 h-4 w-4" />
Ekle
</Button>
</DataTable>
</>
)
}
Expand Down
151 changes: 151 additions & 0 deletions src/pages/settings/advanced/certificates/retrieve.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
import { useState } from "react"
import { useRouter } from "next/router"
import { apiService } from "@/services"
import { DownloadCloudIcon, Save } from "lucide-react"

import { ICertificateDetails } from "@/types/certificate"
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
import PageHeader from "@/components/ui/page-header"
import { useToast } from "@/components/ui/use-toast"

export default function CertificateInformation() {
const { toast } = useToast()
const router = useRouter()

const [loading, setLoading] = useState<boolean>(false)
const [data, setData] = useState<ICertificateDetails>()
const [ipAddress, setIpAddress] = useState<string>("")
const [port, setPort] = useState<string>("")

const fetchDetails = async () => {
setLoading(true)

apiService
.getInstance()
.post<ICertificateDetails>(`/settings/advanced/certificates/retrieve`, {
hostname: ipAddress,
port: port,
})
.then((res) => {
setData(res.data)
})
.catch(() => {
toast({
title: "Hata",
description: "Sertifika detayları getirilirken bir hata oluştu.",
variant: "destructive",
})
})
.finally(() => {
setLoading(false)
})
}

const createCertificate = async () => {
setLoading(true)

apiService
.getInstance()
.post<ICertificateDetails>(`/settings/advanced/certificates`, {
hostname: ipAddress,
port: port,
})
.then((res) => {
toast({
title: "Başarılı",
description: "Sertifika başarıyla oluşturuldu.",
})
setTimeout(() => {
router.push("/settings/advanced/certificates")
}, 1000)
})
.catch(() => {
toast({
title: "Hata",
description: "Sertifika oluşturulurken bir hata oluştu.",
variant: "destructive",
})
})
.finally(() => {
setLoading(false)
})
}

return (
<>
<PageHeader
title="Sertifika Ekle"
description="Hostname ve port bilgisini sağladığınız sunucunun sertifikası Liman sistemine aktarılacaktır."
/>

<div className="p-8 pt-0">
<div className="grid grid-cols-2 gap-6">
<div className="space-y-2">
<h2 className="border-b w-full font-semibold text-lg mb-3">
İstemci Detayları
</h2>
<Label>IP Adresi</Label>
<Input
value={ipAddress}
onChange={(e) => setIpAddress(e.target.value)}
/>
<Button onClick={fetchDetails} className="mb-10" disabled={loading}>
<DownloadCloudIcon className="h-4 w-4 mr-2" /> Sertifika
Detaylarını Getir
</Button>
</div>
<div className="space-y-2 pt-[40px]">
<Label>Port</Label>
<Input value={port} onChange={(e) => setPort(e.target.value)} />
</div>

<div className="space-y-2">
<h2 className="border-b w-full font-semibold text-lg mb-3">
Geçerlilik Süresi
</h2>
<Label>Başlangıç</Label>
<Input value={data?.valid_from} disabled />
</div>

<div className="space-y-2 pt-[40px]">
<Label>Bitiş</Label>
<Input value={data?.valid_to} disabled />
</div>

<div className="space-y-2">
<h2 className="border-b w-full font-semibold text-lg mb-3">
Genel Detaylar
</h2>
<Label>İstemci</Label>
<Input value={data?.issuer_cn} disabled />
</div>

<div className="space-y-2 pt-[40px]">
<Label>Otorite</Label>
<Input value={data?.issuer_dc} disabled />
</div>

<div className="space-y-2">
<Label>İstemci Parmak İzi</Label>
<Input value={data?.subject_key_identifier} disabled />

<Button
onClick={createCertificate}
className="mb-10"
disabled={loading || !data || Object.keys(data).length == 0}
>
<Save className="h-4 w-4 mr-2" /> Kaydet
</Button>
</div>

<div className="space-y-2">
<Label>Otorite Parmak İzi</Label>
<Input value={data?.authority_key_identifier} disabled />
</div>
</div>
</div>
</>
)
}
4 changes: 2 additions & 2 deletions src/pages/settings/advanced/dns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ const AdvancedDnsSettingsPage: NextPageWithLayout = () => {
.then(() => {
toast({
title: "Başarılı",
description: "Keycloak ayarları başarıyla kaydedildi.",
description: "DNS ayarları başarıyla kaydedildi.",
})
})
.catch(() => {
toast({
title: "Hata",
description: "Keycloak ayarları kaydedilirken bir hata oluştu.",
description: "DNS ayarları kaydedilirken bir hata oluştu.",
variant: "destructive",
})
})
Expand Down
11 changes: 11 additions & 0 deletions src/types/certificate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,14 @@ export interface ICertificate {
created_at: string
updated_at: string
}

export interface ICertificateDetails {
ip_address: string
port: number
valid_to: string
valid_from: string
issuer_cn: string
issuer_dc: string
authority_key_identifier: string
subject_key_identifier: string
}

0 comments on commit 6ea5879

Please sign in to comment.