From c680f5aa71b08e978444df07f93c381f9d47ab82 Mon Sep 17 00:00:00 2001
From: Sebastian <sebasjm@gmail.com>
Date: Mon, 5 Jun 2023 10:04:09 -0300
Subject: rename aml

---
 .../aml-backoffice-ui/src/handlers/InputDate.tsx   | 37 ++++++++++++++++++++++
 1 file changed, 37 insertions(+)
 create mode 100644 packages/aml-backoffice-ui/src/handlers/InputDate.tsx

(limited to 'packages/aml-backoffice-ui/src/handlers/InputDate.tsx')

diff --git a/packages/aml-backoffice-ui/src/handlers/InputDate.tsx b/packages/aml-backoffice-ui/src/handlers/InputDate.tsx
new file mode 100644
index 000000000..1fd81aad9
--- /dev/null
+++ b/packages/aml-backoffice-ui/src/handlers/InputDate.tsx
@@ -0,0 +1,37 @@
+import { AbsoluteTime } from "@gnu-taler/taler-util";
+import { InputLine, UIFormProps } from "./InputLine.js";
+import { CalendarIcon } from "@heroicons/react/24/outline";
+import { VNode, h } from "preact";
+import { format, parse } from "date-fns";
+
+export function InputDate<T extends object, K extends keyof T>(
+  props: { pattern?: string } & UIFormProps<T, K>,
+): VNode {
+  const pattern = props.pattern ?? "dd/MM/yyyy";
+  return (
+    <InputLine<T, K>
+      type="text"
+      after={{
+        type: "icon",
+        icon: <CalendarIcon class="h-6 w-6" />,
+      }}
+      converter={{
+        //@ts-ignore
+        fromStringUI: (v): AbsoluteTime => {
+          if (!v) return AbsoluteTime.never();
+          const t_ms = parse(v, pattern, Date.now()).getTime();
+          return AbsoluteTime.fromMilliseconds(t_ms);
+        },
+        //@ts-ignore
+        toStringUI: (v: AbsoluteTime) => {
+          return !v || !v.t_ms
+            ? ""
+            : v.t_ms === "never"
+            ? "never"
+            : format(v.t_ms, pattern);
+        },
+      }}
+      {...props}
+    />
+  );
+}
-- 
cgit v1.2.3

