mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-16 23:55:20 +00:00
Show button to share feedback about GitBook Open when in preview mode (#149)
* Show button to share feedback * Lint
This commit is contained in:
@@ -60,9 +60,7 @@ export default async function ContentLayout(props: {
|
||||
</React.Suspense>
|
||||
) : null}
|
||||
|
||||
{content.revisionId || content.changeRequestId ? (
|
||||
<AdminToolbar content={content} />
|
||||
) : null}
|
||||
<AdminToolbar space={space} content={content} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { Space } from '@gitbook/api';
|
||||
import { headers } from 'next/headers';
|
||||
import React from 'react';
|
||||
|
||||
import { ContentPointer, getChangeRequest, getRevision, getRevisionPages } from '@/lib/api';
|
||||
@@ -5,13 +7,40 @@ import { tcls } from '@/lib/tailwind';
|
||||
|
||||
interface AdminToolbarProps {
|
||||
content: ContentPointer;
|
||||
space: Space;
|
||||
}
|
||||
|
||||
/**
|
||||
* Toolbar with information for the content admin when previewing a revision or change-request.
|
||||
*/
|
||||
export function AdminToolbar(props: AdminToolbarProps) {
|
||||
const { content } = props;
|
||||
const { content, space } = props;
|
||||
const headersSet = headers();
|
||||
|
||||
const toolbar = (() => {
|
||||
if (content.changeRequestId) {
|
||||
return (
|
||||
<ChangeRequestToolbar
|
||||
spaceId={content.spaceId}
|
||||
changeRequestId={content.changeRequestId}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
if (content.revisionId) {
|
||||
return <RevisionToolbar spaceId={content.spaceId} revisionId={content.revisionId} />;
|
||||
}
|
||||
|
||||
if (headersSet.get('x-gitbook-mode') === 'multi-id') {
|
||||
return <ShareFeedbackToolbar space={space} />;
|
||||
}
|
||||
|
||||
return null;
|
||||
})();
|
||||
|
||||
if (!toolbar) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
@@ -32,17 +61,7 @@ export function AdminToolbar(props: AdminToolbarProps) {
|
||||
'border-slate-300',
|
||||
)}
|
||||
>
|
||||
<React.Suspense fallback={null}>
|
||||
{content.changeRequestId ? (
|
||||
<ChangeRequestToolbar
|
||||
spaceId={content.spaceId}
|
||||
changeRequestId={content.changeRequestId}
|
||||
/>
|
||||
) : null}
|
||||
{content.revisionId ? (
|
||||
<RevisionToolbar spaceId={content.spaceId} revisionId={content.revisionId} />
|
||||
) : null}
|
||||
</React.Suspense>
|
||||
<React.Suspense fallback={null}>{toolbar}</React.Suspense>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -71,6 +90,18 @@ async function RevisionToolbar(props: { spaceId: string; revisionId: string }) {
|
||||
);
|
||||
}
|
||||
|
||||
async function ShareFeedbackToolbar(props: { space: Space }) {
|
||||
const { space } = props;
|
||||
|
||||
return (
|
||||
<ToolbarButton
|
||||
href={`https://survey.refiner.io/e61q1m-dz5gpn?response_organization_id=${space.organization}&response_space_id=${space.id}&response_org_id=${space.organization}&contact_space=${space.id}&response_source=open-preview-feedback`}
|
||||
>
|
||||
Share feedback about the new version
|
||||
</ToolbarButton>
|
||||
);
|
||||
}
|
||||
|
||||
function ToolbarButton(props: { href: string; children: React.ReactNode }) {
|
||||
const { href, children } = props;
|
||||
|
||||
|
||||
@@ -157,6 +157,7 @@ export async function middleware(request: NextRequest) {
|
||||
headers.set('x-forwarded-host', inputURL.host);
|
||||
headers.set('origin', inputURL.origin);
|
||||
headers.set('x-gitbook-token', resolved.apiToken);
|
||||
headers.set('x-gitbook-mode', mode);
|
||||
headers.set('x-gitbook-origin-basepath', originBasePath);
|
||||
headers.set('x-gitbook-basepath', joinPath(originBasePath, resolved.basePath));
|
||||
if (resolved.revision) {
|
||||
|
||||
Reference in New Issue
Block a user