import { Checkbox, Link, PrimaryButton, Stack, Text } from "office-ui-fabric-react"; import React, { FunctionComponent, useEffect, useState } from "react"; import { CodeOfConductEndpoints, HttpStatusCodes } from "../../../../Common/Constants"; import { getErrorMessage, getErrorStack, handleError } from "../../../../Common/ErrorHandlingUtils"; import { JunoClient } from "../../../../Juno/JunoClient"; import { Action } from "../../../../Shared/Telemetry/TelemetryConstants"; import { trace, traceFailure, traceStart, traceSuccess } from "../../../../Shared/Telemetry/TelemetryProcessor"; export interface CodeOfConductComponentProps { junoClient: JunoClient; onAcceptCodeOfConduct: (result: boolean) => void; } export const CodeOfConductComponent: FunctionComponent = ({ junoClient, onAcceptCodeOfConduct, }: CodeOfConductComponentProps) => { const descriptionPara1 = "Azure Cosmos DB Notebook Gallery - Code of Conduct"; const descriptionPara2 = "The notebook public gallery contains notebook samples shared by users of Azure Cosmos DB."; const descriptionPara3 = "In order to view and publish your samples to the gallery, you must accept the "; const link1: { label: string; url: string } = { label: "code of conduct.", url: CodeOfConductEndpoints.codeOfConduct, }; const [readCodeOfConduct, setReadCodeOfConduct] = useState(false); const acceptCodeOfConduct = async (): Promise => { const startKey = traceStart(Action.NotebooksGalleryAcceptCodeOfConduct); try { const response = await junoClient.acceptCodeOfConduct(); if (response.status !== HttpStatusCodes.OK && response.status !== HttpStatusCodes.NoContent) { throw new Error(`Received HTTP ${response.status} when accepting code of conduct`); } traceSuccess(Action.NotebooksGalleryAcceptCodeOfConduct, {}, startKey); onAcceptCodeOfConduct(response.data); } catch (error) { traceFailure( Action.NotebooksGalleryAcceptCodeOfConduct, { error: getErrorMessage(error), errorStack: getErrorStack(error), }, startKey ); handleError(error, "CodeOfConductComponent/acceptCodeOfConduct", "Failed to accept code of conduct"); } }; const onChangeCheckbox = (): void => { setReadCodeOfConduct(!readCodeOfConduct); }; useEffect(() => { trace(Action.NotebooksGalleryViewCodeOfConduct); }, []); return ( {descriptionPara1} {descriptionPara2} {descriptionPara3} {link1.label} await acceptCodeOfConduct()} tabIndex={0} className="genericPaneSubmitBtn" text="Continue" disabled={!readCodeOfConduct} /> ); };