import styled from "styled-components"; import * as React from "react"; import { Helmet } from "react-helmet"; import ScrollToTopOnMount from "../../utility/ScrollToTop"; import gql from "graphql-tag"; import { Link, withRouter, RouteComponentProps } from "react-router-dom"; import { formatRoute } from "react-router-named-routes"; import { Query } from "react-apollo"; import { BoostForm } from "@joincivil/sdk"; import { EthAddress, CharterData } from "@joincivil/typescript-types"; import { colors, Tabs, Tab, LoadingMessage, withNewsroomChannel, NewsroomChannelInjectedProps, CivilContext, ICivilContext, } from "@joincivil/components"; import { NewsroomManager, ManageContractMembers } from "@joincivil/newsroom-signup"; import { routes } from "../../../constants"; import { getListingPhaseState } from "../../../selectors"; import { LISTING_QUERY, transformGraphQLDataIntoListing } from "@joincivil/utils"; import { UserManagementPageLayout, UserManagementSection, UserManagementTabNav, UserManagementTabs, } from "../UserManagement"; import { ManageNewsoomTitleText, EditCharterTabText, EditCharterTitleText, SmartContractTabText, SmartContractTitleText, LaunchBoostTabText, LaunchBoostTitleText, } from "./ManageNewsroomTextComponents"; import { ManageNewsroomSmartContractStyles } from "./ManageNewsroomStyledComponents"; const Notice = styled.div` max-width: 800px; margin: 0 auto; padding: 48px 16px; text-align: center; color: ${colors.primary.CIVIL_GRAY_0}; font-size: 16px; line-height: 25px; font-family: ${props => props.theme.sansSerifFont}; `; const NotAdminNotice = styled(Notice)` text-align: left; `; const ManageQuery = gql` query($id: String!) { channelsGetByID(id: $id) { id currentUserIsAdmin newsroom { contractAddress multisigAddress charter { name newsroomUrl logoUrl tagline mission { purpose structure revenue encumbrances miscellaneous } socialUrls { twitter facebook } roster { name role bio ethAddress avatarUrl signature socialUrls { twitter facebook } } } } } } `; interface ManageQueryData { channelsGetByID: { id: string; currentUserIsAdmin: boolean; newsroom: { contractAddress: EthAddress; multisigAddress: EthAddress; charter: Partial; }; }; } interface ManageQueryVariables { id: string; } export interface ManageParams { activeTab?: "edit-charter" | "smart-contract" | "launch-boost"; } const TABS = ["edit-charter", "smart-contract", "launch-boost"]; export interface ManageNewsroomOwnProps extends RouteComponentProps { newsroomAddress: string; } const ManageNewsroomComponent: React.FunctionComponent< ManageNewsroomOwnProps & NewsroomChannelInjectedProps > = props => { const civilContext = React.useContext(CivilContext); if (civilContext.auth.loading) { return Loading Permissions; } else if (!civilContext.auth.currentUser) { return (

Please Sign Up or Log In to manage your newsroom.

); } // Load tab from path: const [activeTabIndex, setActiveTabIndex] = React.useState(0); React.useEffect(() => { const activeTab = props.match.params.activeTab || "edit-charter"; if (TABS[activeTabIndex] !== activeTab) { setActiveTabIndex(TABS.indexOf(activeTab)); } }, [props.match.params.activeTab]); return ( query={ManageQuery} variables={{ id: props.channelData.id, }} > {({ loading, data, error }) => { if (loading) { return Loading your Newsroom; } else if (error) { console.error("error querying channelsGetByID:", error); return ( <> Error loading newsroom: {error.message || JSON.stringify(error)} ); } else if (!data || !data.channelsGetByID) { console.error("error querying channelsGetByID: no data returned"); return <>Error loading newsroom: no newsroom data returned; } else if (!data.channelsGetByID.currentUserIsAdmin) { return (

Your account with ETH address {civilContext.auth.currentUser.ethAddress} doesn't have permissions to manage the newsroom "{data.channelsGetByID.newsroom.charter.name}". You can view the newsrooms you have access to on your Newsroom Dashboard. Please verify that you are logged in to the correct Civil account and ethereum wallet.

Alternately, please contact the newsroom and request that an officer add your account.

View newsroom information.

); } const newsroom = data.channelsGetByID.newsroom; const listingRoute = formatRoute(routes.LISTING, { listingAddress: props.newsroomAddress }); const charter = data.channelsGetByID.newsroom.charter; return ( {({ loading: listingLoading, error: listingError, data: listingData }: any) => { if (listingLoading) { return Loading your Newsroom; } if (listingError) { console.error("error querying listing:", listingError); return ( <> Error loading newsroom listing: {listingError.message || JSON.stringify(listingError)} ); } const listing = transformGraphQLDataIntoListing(listingData.tcrListing, props.newsroomAddress); const listingPhaseState = getListingPhaseState(listing); return ( <> }> { props.history.push( formatRoute(props.match.path, { newsroomAddress: props.newsroomAddress, activeTab: TABS[tab], }), ); }} flex={true} > }> }> }> }> }> }> ); }} ); }} ); }; export const ManageNewsroom = withRouter(withNewsroomChannel(ManageNewsroomComponent));