feat: check tracking code component
This commit is contained in:
44
src/components/CheckTrackingCode/CheckTrackingCode.tsx
Normal file
44
src/components/CheckTrackingCode/CheckTrackingCode.tsx
Normal file
@@ -0,0 +1,44 @@
|
||||
import { ArrowTopRightOnSquareIcon } from "@heroicons/react/24/outline";
|
||||
import { useRef } from "react";
|
||||
|
||||
type CheckTrackingCodeProps = {
|
||||
tracking?: string | number | null;
|
||||
className?: string;
|
||||
};
|
||||
|
||||
export default function CheckTrackingCode({
|
||||
tracking,
|
||||
className = "",
|
||||
}: CheckTrackingCodeProps) {
|
||||
const formRef = useRef<HTMLFormElement>(null);
|
||||
const safeTracking = tracking ? String(tracking) : "";
|
||||
|
||||
const handleSubmit = () => {
|
||||
if (!safeTracking) return;
|
||||
formRef.current?.submit();
|
||||
};
|
||||
|
||||
if (!safeTracking) {
|
||||
return <span>-</span>;
|
||||
}
|
||||
|
||||
return (
|
||||
<form
|
||||
action="https://e.ivo.ir/Rahgiri/Gidprnt.aspx"
|
||||
method="post"
|
||||
target="_blank"
|
||||
ref={formRef}
|
||||
className={`inline-flex ${className}`}
|
||||
>
|
||||
<input name="gid" type="hidden" value={safeTracking} />
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleSubmit}
|
||||
className="group inline-flex cursor-pointer items-center gap-1.5 rounded-xl border border-primary-500/30 bg-gradient-to-r from-primary-500/10 to-primary-500/20 px-3 py-1.5 text-xs font-medium text-primary-700 transition-all duration-200 hover:from-primary-500/20 hover:to-primary-500/30 hover:shadow-sm dark:border-primary-200/20 dark:from-primary-100/10 dark:to-primary-100/20 dark:text-primary-200"
|
||||
>
|
||||
<span className="tracking-wide">{safeTracking}</span>
|
||||
<ArrowTopRightOnSquareIcon className="h-3.5 w-3.5 transition-transform duration-200 group-hover:-translate-y-0.5 group-hover:translate-x-0.5" />
|
||||
</button>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user