Karyawan · Impor dari Excel

Import employees from Excel in 4 steps: upload, match columns, check and fix rows, result.

$ npx shadcn@latest add https://mahrdesign.faizintifada.com/r/screen-karyawan-impor.json
Buka layar penuh

When to use

  • Adding many employees at once (a new company, 10+ people): "Impor dari Excel" in the Karyawan header and in the first-run card.
  • Any spreadsheet, not only the MaHR template: step 2 maps every file column to a MaHR column.

When not to use

  • One or two people → Tambah karyawan (the Sheet on Karyawan · Daftar).
  • Changing existing employees → Karyawan · Detail (the Ubah panels). The import adds people; it never updates them (duplicates are errors).

Built from

Usage

The screen is the page content only. Put it inside AppShell (once, in your layout) and pass your data.

page.tsx
import { AppShell } from "@/components/mahr/app-shell"import { KaryawanImpor } from "@/components/screens/karyawan-impor/karyawan-impor"import Link from "next/link"// One route, the step in the URL (?langkah=unggah|cocokkan|cek|selesai), the draft on the// server under an import id: browser Back and a refresh lose nothing.export default function Page({ searchParams }: { searchParams: { langkah?: string; id?: string } }) {  const imp = useImportDraft(searchParams.id) // file slot, matches, check result, result  const step = (searchParams.langkah ?? "unggah") as ImporStep  return (    <AppShell role="admin" activeItem="karyawan" title="Karyawan" company={company} user={me}>      <KaryawanImpor        step={step}        data={imp.data}        status={imp.checking ? "loading" : imp.checkError ? "error" : "ready"}        error={imp.checkError}        filter={imp.filter}        importing={imp.importing}        importFailed={imp.importFailed}        sendInvites={imp.sendInvites}        onSendInvitesChange={imp.setSendInvites}        onPickFile={(file) => imp.read(file)} // POST /api/employees/import (preview) with progress        onDownloadTemplate={() => download("/template-karyawan-mahr.xlsx")}        onCancel={() => { imp.discard(); router.push("/karyawan") }}        onBack={() => router.push(prevStepUrl(step))}        onNext={() => router.push(nextStepUrl(step))} // step 2 → 3 starts the check        onChangeMatch={imp.match}        onSkipColumn={imp.skip}        onFilterChange={imp.setFilter}        onPageChange={imp.setPage}        onSaveRow={(fix) => imp.fixRow(fix)} // resolve to field errors (e.g. a duplicate email) or nothing        onImport={() => imp.commit()} // POST /api/employees/import (commit), one transaction        onRetry={imp.recheck}        onDownloadFailed={() => download(imp.failedRowsUrl)} // same columns + "Masalah"        onViewNotPayable={() => router.push("/karyawan?belum-bisa-digaji=1")}        onImportAnother={() => router.push("/karyawan/impor")}        listRender={<Link href="/karyawan" />}        helpHref="/bantuan#impor-karyawan"      />    </AppShell>  )}

Installation

Adds the screen, its parts and its types. The components it uses come with it (registry dependencies).

terminal
bunx --bun shadcn@latest add https://mahrdesign.faizintifada.com/r/screen-karyawan-impor.json

API

import { KaryawanImpor } from "@/components/screens/karyawan-impor/karyawan-impor"
PropTypeDefaultDescription
step"unggah" | "cocokkan" | "cek" | "selesai"–The app owns the step (in the URL). The body enters from the direction of travel; header row and action bar stay.
dataImporData–{ mahrColumns, departments, banks, file, matches, cek?, result? }. The screen never reads the file; see types.ts.
data.fileFileSlot: empty · reading { progress } · ready { rows, columns } · error { message }–Step 1 slot (one height in every state). Accept .xlsx and .csv, 5 MB, 1.000 rows; one message per cause with its fix.
data.matchesColumnMatch[]–One per file column: header, 2 samples, target, auto, skipped, note. "Lanjut" is disabled only while a required column (5 + Email kerja or Nomor HP) has no file column.
data.cek · filterCekData · "masalah" | "perbaiki" | "nanti" | "semua"–Counts + the rows of the filter, 10 per page (the app filters and pages).
status · error · onRetry"ready" | "loading" | "error"–Step 3 check: loading = "Memeriksa 48 baris…" + skeletons; error = LoadError with "Kode: IMP-500 · …".
onSaveRow(fix: RowFix) => RowFixErrors | void | Promise<…>–"Simpan baris" in Perbaiki baris. Resolve to field errors (e.g. duplicate email) to keep the panel open and shake them.
importing · importFailed · onImportboolean · boolean · () => void–"Impor 44 karyawan" → "Mengimpor…" (Kembali and Batal impor locked). Failed: danger Callout "Impor gagal", nothing saved, the primary retries.
sendInvites · onSendInvitesChangeboolean · (on) => voidtrue"Kirim undangan login" on step 3: by email, else WhatsApp. Selesai says how many went each way.
onCancel() => void–"Batal impor": at once while nothing was read; else after "Batalkan impor?" (destructive Dialog).
listHref · listRenderstring · ReactElement"/karyawan""Lihat daftar karyawan →": the flow exit, a real link with the primary look (docs/buttons.md).
helpHrefstring"/bantuan#impor-karyawan""Butuh bantuan?" opens in a new tab, so the chosen file is not lost.
onDownloadTemplate · onDownloadFailed · onViewNotPayable · onImportAnother() => void–Template file; failed rows (.xlsx with a "Masalah" column); Daftar filtered on belum bisa digaji; a clean step 1.
defaultUi{ panelRow?, panelFailed?, columnsExpanded?, cancelAsking? }–Start UI state for previews and tests only.