fix: render create action bar in page layout
This commit is contained in:
@@ -2,6 +2,7 @@ import { zodResolver } from "@hookform/resolvers/zod";
|
|||||||
import { useMutation } from "@tanstack/react-query";
|
import { useMutation } from "@tanstack/react-query";
|
||||||
import { useEffect, useMemo, useRef } from "react";
|
import { useEffect, useMemo, useRef } from "react";
|
||||||
import { useForm } from "react-hook-form";
|
import { useForm } from "react-hook-form";
|
||||||
|
import { createPortal } from "react-dom";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
|
|
||||||
import { createOperation } from "../../entities/operation/api";
|
import { createOperation } from "../../entities/operation/api";
|
||||||
@@ -195,7 +196,11 @@ function bytesToBase64(buffer: ArrayBuffer) {
|
|||||||
return window.btoa(binary);
|
return window.btoa(binary);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function OperationForm() {
|
type OperationFormProps = {
|
||||||
|
actionBarContainerId?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function OperationForm({ actionBarContainerId }: OperationFormProps) {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const form = useForm<OperationFormValues>({
|
const form = useForm<OperationFormValues>({
|
||||||
defaultValues: defaultOperationFormValues,
|
defaultValues: defaultOperationFormValues,
|
||||||
@@ -236,6 +241,9 @@ export function OperationForm() {
|
|||||||
}
|
}
|
||||||
}, [activeProtocol]);
|
}, [activeProtocol]);
|
||||||
|
|
||||||
|
const actionBarContainer =
|
||||||
|
actionBarContainerId === undefined ? null : document.getElementById(actionBarContainerId);
|
||||||
|
|
||||||
async function handleDescriptorFileChange(file: File | undefined) {
|
async function handleDescriptorFileChange(file: File | undefined) {
|
||||||
if (file === undefined) {
|
if (file === undefined) {
|
||||||
return;
|
return;
|
||||||
@@ -339,13 +347,15 @@ export function OperationForm() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form
|
<>
|
||||||
className="builder-stack"
|
<form
|
||||||
onSubmit={form.handleSubmit((values) => {
|
className="builder-stack"
|
||||||
creationMutation.mutate(values);
|
id="operation-create-form"
|
||||||
})}
|
onSubmit={form.handleSubmit((values) => {
|
||||||
>
|
creationMutation.mutate(values);
|
||||||
<div className="builder-content">
|
})}
|
||||||
|
>
|
||||||
|
<div className="builder-content">
|
||||||
<section className="builder-card">
|
<section className="builder-card">
|
||||||
<header className="builder-card-header">
|
<header className="builder-card-header">
|
||||||
<div>
|
<div>
|
||||||
@@ -503,17 +513,28 @@ export function OperationForm() {
|
|||||||
: "Failed to create operation"}
|
: "Failed to create operation"}
|
||||||
</div>
|
</div>
|
||||||
) : null}
|
) : null}
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="sticky-action-bar">
|
|
||||||
<div className="sticky-action-copy">
|
|
||||||
<span className="status-pill status-testing">ready to publish later</span>
|
|
||||||
<p>{protocolSummary(activeProtocol)}</p>
|
|
||||||
</div>
|
</div>
|
||||||
<button className="button-primary button-primary-strong" type="submit" disabled={creationMutation.isPending}>
|
</form>
|
||||||
{creationMutation.isPending ? "Creating..." : "Create operation"}
|
|
||||||
</button>
|
{actionBarContainer
|
||||||
</div>
|
? createPortal(
|
||||||
</form>
|
<div className="sticky-action-bar">
|
||||||
|
<div className="sticky-action-copy">
|
||||||
|
<span className="status-pill status-testing">ready to publish later</span>
|
||||||
|
<p>{protocolSummary(activeProtocol)}</p>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
className="button-primary button-primary-strong"
|
||||||
|
type="submit"
|
||||||
|
form="operation-create-form"
|
||||||
|
disabled={creationMutation.isPending}
|
||||||
|
>
|
||||||
|
{creationMutation.isPending ? "Creating..." : "Create operation"}
|
||||||
|
</button>
|
||||||
|
</div>,
|
||||||
|
actionBarContainer,
|
||||||
|
)
|
||||||
|
: null}
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
import { OperationForm } from "../../features/operation-form/operation-form";
|
import { OperationForm } from "../../features/operation-form/operation-form";
|
||||||
|
|
||||||
export function OperationCreatePage() {
|
export function OperationCreatePage() {
|
||||||
return <OperationForm />;
|
return (
|
||||||
|
<div className="create-page-layout">
|
||||||
|
<OperationForm actionBarContainerId="operation-create-action-bar" />
|
||||||
|
<div className="sticky-action-bar-slot" id="operation-create-action-bar" />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -398,6 +398,7 @@ button {
|
|||||||
.page-stack,
|
.page-stack,
|
||||||
.stack-layout,
|
.stack-layout,
|
||||||
.builder-stack,
|
.builder-stack,
|
||||||
|
.create-page-layout,
|
||||||
.service-grid,
|
.service-grid,
|
||||||
.service-method-list {
|
.service-method-list {
|
||||||
display: grid;
|
display: grid;
|
||||||
@@ -872,9 +873,7 @@ button {
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
gap: 16px;
|
gap: 16px;
|
||||||
width: calc(100% + 56px);
|
width: 100%;
|
||||||
margin-left: -28px;
|
|
||||||
margin-right: -28px;
|
|
||||||
padding: 12px 28px;
|
padding: 12px 28px;
|
||||||
border-radius: 0;
|
border-radius: 0;
|
||||||
background: rgba(255, 255, 255, 0.9);
|
background: rgba(255, 255, 255, 0.9);
|
||||||
@@ -894,6 +893,10 @@ button {
|
|||||||
font-size: 12.5px;
|
font-size: 12.5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.sticky-action-bar-slot {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
.field-error {
|
.field-error {
|
||||||
color: #a1422c;
|
color: #a1422c;
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
@@ -1162,9 +1165,6 @@ pre {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.sticky-action-bar {
|
.sticky-action-bar {
|
||||||
width: calc(100% + 32px);
|
|
||||||
margin-left: -16px;
|
|
||||||
margin-right: -16px;
|
|
||||||
padding-left: 16px;
|
padding-left: 16px;
|
||||||
padding-right: 16px;
|
padding-right: 16px;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user