forked from baron/baron-sso
린트 적용3
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import { useMutation } from "@tanstack/react-query";
|
import { useMutation } from "@tanstack/react-query";
|
||||||
|
import type { AxiosError } from "axios";
|
||||||
import { Download, FileText, Loader2, Upload } from "lucide-react";
|
import { Download, FileText, Loader2, Upload } from "lucide-react";
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
@@ -20,7 +21,10 @@ interface OrgChartUploadModalProps {
|
|||||||
onSuccess?: () => void;
|
onSuccess?: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function OrgChartUploadModal({ tenantId, onSuccess }: OrgChartUploadModalProps) {
|
export function OrgChartUploadModal({
|
||||||
|
tenantId,
|
||||||
|
onSuccess,
|
||||||
|
}: OrgChartUploadModalProps) {
|
||||||
const [open, setOpen] = React.useState(false);
|
const [open, setOpen] = React.useState(false);
|
||||||
const [file, setFile] = React.useState<File | null>(null);
|
const [file, setFile] = React.useState<File | null>(null);
|
||||||
const fileInputRef = React.useRef<HTMLInputElement>(null);
|
const fileInputRef = React.useRef<HTMLInputElement>(null);
|
||||||
@@ -28,11 +32,16 @@ export function OrgChartUploadModal({ tenantId, onSuccess }: OrgChartUploadModal
|
|||||||
const mutation = useMutation({
|
const mutation = useMutation({
|
||||||
mutationFn: (file: File) => importOrgChart(tenantId, file),
|
mutationFn: (file: File) => importOrgChart(tenantId, file),
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
toast.success(t("msg.admin.org.import_success", "조직도가 성공적으로 업로드되었습니다."));
|
toast.success(
|
||||||
|
t(
|
||||||
|
"msg.admin.org.import_success",
|
||||||
|
"조직도가 성공적으로 업로드되었습니다.",
|
||||||
|
),
|
||||||
|
);
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
onSuccess?.();
|
onSuccess?.();
|
||||||
},
|
},
|
||||||
onError: (error: any) => {
|
onError: (error: AxiosError<{ error?: string }>) => {
|
||||||
toast.error(t("msg.admin.org.import_error", "조직도 업로드 실패"), {
|
toast.error(t("msg.admin.org.import_error", "조직도 업로드 실패"), {
|
||||||
description: error.response?.data?.error || error.message,
|
description: error.response?.data?.error || error.message,
|
||||||
});
|
});
|
||||||
@@ -54,11 +63,16 @@ export function OrgChartUploadModal({ tenantId, onSuccess }: OrgChartUploadModal
|
|||||||
|
|
||||||
const downloadTemplate = () => {
|
const downloadTemplate = () => {
|
||||||
const headers = "email,name,organization,position,jobtitle,is_owner";
|
const headers = "email,name,organization,position,jobtitle,is_owner";
|
||||||
const example = "ceo@example.com,홍길동,경영진,대표이사,경영총괄,true
|
const example = `ceo@example.com,홍길동,경영진,대표이사,경영총괄,true
|
||||||
cto@example.com,이몽룡,기술부문,이사,기술총괄,true
|
cto@example.com,이몽룡,기술부문,이사,기술총괄,true
|
||||||
user1@example.com,성춘향,기술부문/개발팀,팀원,프론트엔드 개발,false";
|
user1@example.com,성춘향,기술부문/개발팀,팀원,프론트엔드 개발,false`;
|
||||||
const blob = new Blob([`${headers}
|
const blob = new Blob(
|
||||||
${example}`], { type: "text/csv" });
|
[
|
||||||
|
`${headers}
|
||||||
|
${example}`,
|
||||||
|
],
|
||||||
|
{ type: "text/csv" },
|
||||||
|
);
|
||||||
const url = URL.createObjectURL(blob);
|
const url = URL.createObjectURL(blob);
|
||||||
const a = document.createElement("a");
|
const a = document.createElement("a");
|
||||||
a.href = url;
|
a.href = url;
|
||||||
@@ -77,15 +91,25 @@ ${example}`], { type: "text/csv" });
|
|||||||
</DialogTrigger>
|
</DialogTrigger>
|
||||||
<DialogContent>
|
<DialogContent>
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle>{t("ui.admin.org.import_title", "조직도 일괄 등록")}</DialogTitle>
|
<DialogTitle>
|
||||||
|
{t("ui.admin.org.import_title", "조직도 일괄 등록")}
|
||||||
|
</DialogTitle>
|
||||||
<DialogDescription>
|
<DialogDescription>
|
||||||
{t("msg.admin.org.import_description", "CSV 파일을 업로드하여 조직 계층과 멤버를 한 번에 구성합니다.")}
|
{t(
|
||||||
|
"msg.admin.org.import_description",
|
||||||
|
"CSV 파일을 업로드하여 조직 계층과 멤버를 한 번에 구성합니다.",
|
||||||
|
)}
|
||||||
</DialogDescription>
|
</DialogDescription>
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
|
|
||||||
<div className="space-y-4 py-4">
|
<div className="space-y-4 py-4">
|
||||||
<div className="flex justify-between items-center">
|
<div className="flex justify-between items-center">
|
||||||
<Button variant="ghost" size="sm" onClick={downloadTemplate} className="gap-2">
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="sm"
|
||||||
|
onClick={downloadTemplate}
|
||||||
|
className="gap-2"
|
||||||
|
>
|
||||||
<Download size={14} />
|
<Download size={14} />
|
||||||
{t("ui.admin.org.download_template", "템플릿 다운로드")}
|
{t("ui.admin.org.download_template", "템플릿 다운로드")}
|
||||||
</Button>
|
</Button>
|
||||||
@@ -96,8 +120,14 @@ ${example}`], { type: "text/csv" });
|
|||||||
ref={fileInputRef}
|
ref={fileInputRef}
|
||||||
onChange={handleFileChange}
|
onChange={handleFileChange}
|
||||||
/>
|
/>
|
||||||
<Button onClick={() => fileInputRef.current?.click()} variant="secondary" size="sm">
|
<Button
|
||||||
{file ? t("ui.common.change_file", "파일 변경") : t("ui.common.select_file", "파일 선택")}
|
onClick={() => fileInputRef.current?.click()}
|
||||||
|
variant="secondary"
|
||||||
|
size="sm"
|
||||||
|
>
|
||||||
|
{file
|
||||||
|
? t("ui.common.change_file", "파일 변경")
|
||||||
|
: t("ui.common.select_file", "파일 선택")}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -106,19 +136,23 @@ ${example}`], { type: "text/csv" });
|
|||||||
<FileText className="text-primary" />
|
<FileText className="text-primary" />
|
||||||
<div className="flex-1 min-w-0">
|
<div className="flex-1 min-w-0">
|
||||||
<div className="font-medium truncate">{file.name}</div>
|
<div className="font-medium truncate">{file.name}</div>
|
||||||
<div className="text-xs text-muted-foreground">{(file.size / 1024).toFixed(1)} KB</div>
|
<div className="text-xs text-muted-foreground">
|
||||||
|
{(file.size / 1024).toFixed(1)} KB
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<DialogFooter>
|
<DialogFooter>
|
||||||
<Button
|
<Button
|
||||||
onClick={handleUpload}
|
onClick={handleUpload}
|
||||||
disabled={!file || mutation.isPending}
|
disabled={!file || mutation.isPending}
|
||||||
className="w-full sm:w-auto"
|
className="w-full sm:w-auto"
|
||||||
>
|
>
|
||||||
{mutation.isPending && <Loader2 size={16} className="mr-2 animate-spin" />}
|
{mutation.isPending && (
|
||||||
|
<Loader2 size={16} className="mr-2 animate-spin" />
|
||||||
|
)}
|
||||||
{t("ui.admin.org.start_import", "임포트 시작")}
|
{t("ui.admin.org.start_import", "임포트 시작")}
|
||||||
</Button>
|
</Button>
|
||||||
</DialogFooter>
|
</DialogFooter>
|
||||||
|
|||||||
@@ -477,7 +477,8 @@ function UserCreatePage() {
|
|||||||
/>
|
/>
|
||||||
{errors.metadata?.[field.key] && (
|
{errors.metadata?.[field.key] && (
|
||||||
<p className="text-xs text-destructive">
|
<p className="text-xs text-destructive">
|
||||||
{(errors.metadata[field.key] as any).message}
|
{(errors.metadata[field.key] as { message?: string })
|
||||||
|
?.message}
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -9,7 +9,11 @@ import {
|
|||||||
Users,
|
Users,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { useForm } from "react-hook-form";
|
import {
|
||||||
|
type FieldErrors,
|
||||||
|
type UseFormRegister,
|
||||||
|
useForm,
|
||||||
|
} from "react-hook-form";
|
||||||
import { Link, useNavigate, useParams } from "react-router-dom";
|
import { Link, useNavigate, useParams } from "react-router-dom";
|
||||||
import { Button } from "../../components/ui/button";
|
import { Button } from "../../components/ui/button";
|
||||||
import {
|
import {
|
||||||
@@ -22,6 +26,7 @@ import {
|
|||||||
import { Input } from "../../components/ui/input";
|
import { Input } from "../../components/ui/input";
|
||||||
import { Label } from "../../components/ui/label";
|
import { Label } from "../../components/ui/label";
|
||||||
import {
|
import {
|
||||||
|
type TenantSummary,
|
||||||
type UserUpdateRequest,
|
type UserUpdateRequest,
|
||||||
fetchMe,
|
fetchMe,
|
||||||
fetchTenant,
|
fetchTenant,
|
||||||
@@ -40,7 +45,7 @@ type UserSchemaField = {
|
|||||||
validation?: string;
|
validation?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
type UserFormValues = UserUpdateRequest & { metadata: Record<string, unknown> };
|
type UserFormValues = UserUpdateRequest & { metadata: Record<string, Record<string, unknown>> };
|
||||||
|
|
||||||
// [New] Component for per-tenant profile/schema management
|
// [New] Component for per-tenant profile/schema management
|
||||||
function TenantProfileCard({
|
function TenantProfileCard({
|
||||||
@@ -49,9 +54,9 @@ function TenantProfileCard({
|
|||||||
errors,
|
errors,
|
||||||
isAdmin,
|
isAdmin,
|
||||||
}: {
|
}: {
|
||||||
tenant: any;
|
tenant: TenantSummary;
|
||||||
register: any;
|
register: UseFormRegister<UserFormValues>;
|
||||||
errors: any;
|
errors: FieldErrors<UserFormValues>;
|
||||||
isAdmin: boolean;
|
isAdmin: boolean;
|
||||||
}) {
|
}) {
|
||||||
const { data: detail, isLoading } = useQuery({
|
const { data: detail, isLoading } = useQuery({
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||||
|
import type { AxiosError } from "axios";
|
||||||
import { FolderTree, Loader2, Search } from "lucide-react";
|
import { FolderTree, Loader2, Search } from "lucide-react";
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
@@ -70,7 +71,7 @@ export function UserBulkMoveGroupModal({
|
|||||||
setOpen(false);
|
setOpen(false);
|
||||||
onSuccess?.();
|
onSuccess?.();
|
||||||
},
|
},
|
||||||
onError: (error: any) => {
|
onError: (error: AxiosError<{ error?: string }>) => {
|
||||||
toast.error(t("msg.admin.users.bulk.move_error", "부서 이동 실패"), {
|
toast.error(t("msg.admin.users.bulk.move_error", "부서 이동 실패"), {
|
||||||
description: error.response?.data?.error || error.message,
|
description: error.response?.data?.error || error.message,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -195,8 +195,8 @@ ${example}`,
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{previewData.slice(0, 10).map((u, i) => (
|
{previewData.slice(0, 10).map((u) => (
|
||||||
<tr key={i} className="border-t">
|
<tr key={u.email} className="border-t">
|
||||||
<td className="p-2">{u.email}</td>
|
<td className="p-2">{u.email}</td>
|
||||||
<td className="p-2">{u.name}</td>
|
<td className="p-2">{u.name}</td>
|
||||||
<td className="p-2">{u.companyCode || "-"}</td>
|
<td className="p-2">{u.companyCode || "-"}</td>
|
||||||
@@ -241,9 +241,9 @@ ${example}`,
|
|||||||
|
|
||||||
<ScrollArea className="h-[250px] rounded-md border">
|
<ScrollArea className="h-[250px] rounded-md border">
|
||||||
<div className="p-2 space-y-2">
|
<div className="p-2 space-y-2">
|
||||||
{results.map((r, i) => (
|
{results.map((r) => (
|
||||||
<div
|
<div
|
||||||
key={i}
|
key={r.email}
|
||||||
className="flex items-start gap-3 p-2 rounded border bg-card text-sm"
|
className="flex items-start gap-3 p-2 rounded border bg-card text-sm"
|
||||||
>
|
>
|
||||||
{r.success ? (
|
{r.success ? (
|
||||||
|
|||||||
@@ -13,11 +13,12 @@ export function parseUserCSV(text: string): BulkUserItem[] {
|
|||||||
if (!lines[i].trim()) continue;
|
if (!lines[i].trim()) continue;
|
||||||
|
|
||||||
const values = lines[i].split(",").map((v) => v.trim());
|
const values = lines[i].split(",").map((v) => v.trim());
|
||||||
const item: any = { metadata: {} };
|
const item: Record<string, any> = { metadata: {} };
|
||||||
|
|
||||||
headers.forEach((header, index) => {
|
for (let index = 0; index < headers.length; index++) {
|
||||||
|
const header = headers[index];
|
||||||
const value = values[index];
|
const value = values[index];
|
||||||
if (value === undefined || value === "") return;
|
if (value === undefined || value === "") continue;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
[
|
[
|
||||||
@@ -34,7 +35,7 @@ export function parseUserCSV(text: string): BulkUserItem[] {
|
|||||||
} else {
|
} else {
|
||||||
item.metadata[header] = value;
|
item.metadata[header] = value;
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
if (item.email && item.name) {
|
if (item.email && item.name) {
|
||||||
data.push(item as BulkUserItem);
|
data.push(item as BulkUserItem);
|
||||||
|
|||||||
Reference in New Issue
Block a user