2022-10-20 08:34:38 +00:00
|
|
|
import {makeT} from 'app/client/lib/localization';
|
2022-06-03 14:58:07 +00:00
|
|
|
import {getLoginOrSignupUrl, urlState} from 'app/client/models/gristUrlState';
|
2021-07-28 19:02:06 +00:00
|
|
|
import {HomeModel} from 'app/client/models/HomeModel';
|
2022-06-03 14:58:07 +00:00
|
|
|
import {productPill} from 'app/client/ui/AppHeader';
|
2020-10-02 15:10:00 +00:00
|
|
|
import * as css from 'app/client/ui/DocMenuCss';
|
|
|
|
import {createDocAndOpen, importDocAndOpen} from 'app/client/ui/HomeLeftPane';
|
2022-06-03 14:58:07 +00:00
|
|
|
import {manageTeamUsersApp} from 'app/client/ui/OpenUserManager';
|
|
|
|
import {bigBasicButton, cssButton} from 'app/client/ui2018/buttons';
|
2022-09-06 01:51:57 +00:00
|
|
|
import {testId, theme, vars} from 'app/client/ui2018/cssVars';
|
2020-10-02 15:10:00 +00:00
|
|
|
import {icon} from 'app/client/ui2018/icons';
|
|
|
|
import {cssLink} from 'app/client/ui2018/links';
|
2022-06-07 21:14:35 +00:00
|
|
|
import {commonUrls, shouldHideUiElement} from 'app/common/gristUrls';
|
2022-06-03 14:58:07 +00:00
|
|
|
import {FullUser} from 'app/common/LoginSessionAPI';
|
|
|
|
import * as roles from 'app/common/roles';
|
2022-08-03 10:35:45 +00:00
|
|
|
import {Computed, dom, DomContents, styled} from 'grainjs';
|
2020-10-02 15:10:00 +00:00
|
|
|
|
2022-10-28 16:11:08 +00:00
|
|
|
const t = makeT('HomeIntro');
|
2022-06-07 21:14:35 +00:00
|
|
|
|
2020-10-02 15:10:00 +00:00
|
|
|
export function buildHomeIntro(homeModel: HomeModel): DomContents {
|
2022-08-03 10:35:45 +00:00
|
|
|
const isViewer = homeModel.app.currentOrg?.access === roles.VIEWER;
|
2020-10-02 15:10:00 +00:00
|
|
|
const user = homeModel.app.currentValidUser;
|
2022-08-03 10:35:45 +00:00
|
|
|
const isAnonym = !user;
|
|
|
|
const isPersonal = !homeModel.app.isTeamSite;
|
|
|
|
if (isAnonym) {
|
2022-06-03 14:58:07 +00:00
|
|
|
return makeAnonIntro(homeModel);
|
2022-08-03 10:35:45 +00:00
|
|
|
} else if (isPersonal) {
|
|
|
|
return makePersonalIntro(homeModel, user);
|
|
|
|
} else { // isTeamSite
|
|
|
|
if (isViewer) {
|
|
|
|
return makeViewerTeamSiteIntro(homeModel);
|
|
|
|
} else {
|
|
|
|
return makeTeamSiteIntro(homeModel);
|
|
|
|
}
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-07 09:52:40 +00:00
|
|
|
export function buildWorkspaceIntro(homeModel: HomeModel): DomContents {
|
|
|
|
const isViewer = homeModel.currentWS.get()?.access === roles.VIEWER;
|
|
|
|
const isAnonym = !homeModel.app.currentValidUser;
|
2022-12-06 13:57:29 +00:00
|
|
|
const emptyLine = cssIntroLine(testId('empty-workspace-info'), t("This workspace is empty."));
|
2022-09-07 09:52:40 +00:00
|
|
|
if (isAnonym || isViewer) {
|
|
|
|
return emptyLine;
|
|
|
|
} else {
|
|
|
|
return [
|
|
|
|
emptyLine,
|
|
|
|
buildButtons(homeModel, {
|
|
|
|
invite: false,
|
|
|
|
templates: false,
|
|
|
|
import: true,
|
|
|
|
empty: true
|
|
|
|
})
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-03 10:35:45 +00:00
|
|
|
function makeViewerTeamSiteIntro(homeModel: HomeModel) {
|
|
|
|
const personalOrg = Computed.create(null, use => use(homeModel.app.topAppModel.orgs).find(o => o.owner));
|
|
|
|
const docLink = (dom.maybe(personalOrg, org => {
|
|
|
|
return cssLink(
|
|
|
|
urlState().setLinkUrl({org: org.domain ?? undefined}),
|
2022-12-06 13:57:29 +00:00
|
|
|
t("personal site"),
|
2022-08-03 10:35:45 +00:00
|
|
|
testId('welcome-personal-url'));
|
|
|
|
}));
|
|
|
|
return [
|
|
|
|
css.docListHeader(
|
|
|
|
dom.autoDispose(personalOrg),
|
2023-03-27 18:28:40 +00:00
|
|
|
t("Welcome to {{- orgName}}", {orgName: homeModel.app.currentOrgName}),
|
2022-08-03 10:35:45 +00:00
|
|
|
productPill(homeModel.app.currentOrg, {large: true}),
|
|
|
|
testId('welcome-title')
|
|
|
|
),
|
|
|
|
cssIntroLine(
|
|
|
|
testId('welcome-info'),
|
2022-12-06 13:57:29 +00:00
|
|
|
t("You have read-only access to this site. Currently there are no documents."),
|
2022-10-28 16:11:08 +00:00
|
|
|
dom('br'),
|
2022-12-06 13:57:29 +00:00
|
|
|
t("Any documents created in this site will appear here."),
|
2022-10-28 16:11:08 +00:00
|
|
|
),
|
2022-08-03 10:35:45 +00:00
|
|
|
cssIntroLine(
|
2022-12-06 13:57:29 +00:00
|
|
|
t("Interested in using Grist outside of your team? Visit your free "), docLink, '.',
|
2022-08-03 10:35:45 +00:00
|
|
|
testId('welcome-text')
|
|
|
|
)
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2022-06-03 14:58:07 +00:00
|
|
|
function makeTeamSiteIntro(homeModel: HomeModel) {
|
2022-12-06 13:57:29 +00:00
|
|
|
const sproutsProgram = cssLink({href: commonUrls.sproutsProgram, target: '_blank'}, t("Sprouts Program"));
|
2022-06-03 14:58:07 +00:00
|
|
|
return [
|
2022-08-03 10:35:45 +00:00
|
|
|
css.docListHeader(
|
2023-03-27 18:28:40 +00:00
|
|
|
t("Welcome to {{- orgName}}", {orgName: homeModel.app.currentOrgName}),
|
2022-06-03 14:58:07 +00:00
|
|
|
productPill(homeModel.app.currentOrg, {large: true}),
|
2022-08-03 10:35:45 +00:00
|
|
|
testId('welcome-title')
|
|
|
|
),
|
2022-12-06 13:57:29 +00:00
|
|
|
cssIntroLine(t("Get started by inviting your team and creating your first Grist document.")),
|
2022-06-07 21:14:35 +00:00
|
|
|
(shouldHideUiElement('helpCenter') ? null :
|
2022-08-03 10:35:45 +00:00
|
|
|
cssIntroLine(
|
2022-10-28 16:11:08 +00:00
|
|
|
'Learn more in our ', helpCenterLink(), ', or find an expert via our ', sproutsProgram, '.', // TODO i18n
|
2022-08-03 10:35:45 +00:00
|
|
|
testId('welcome-text')
|
|
|
|
)
|
2022-06-07 21:14:35 +00:00
|
|
|
),
|
2022-08-03 10:35:45 +00:00
|
|
|
makeCreateButtons(homeModel)
|
2022-06-03 14:58:07 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
function makePersonalIntro(homeModel: HomeModel, user: FullUser) {
|
|
|
|
return [
|
2023-03-27 18:28:40 +00:00
|
|
|
css.docListHeader(t("Welcome to Grist, {{- name}}!", {name: user.name}), testId('welcome-title')),
|
2022-12-06 13:57:29 +00:00
|
|
|
cssIntroLine(t("Get started by creating your first Grist document.")),
|
2022-06-07 21:14:35 +00:00
|
|
|
(shouldHideUiElement('helpCenter') ? null :
|
2022-12-06 13:57:29 +00:00
|
|
|
cssIntroLine(t("Visit our {{link}} to learn more.", { link: helpCenterLink() }),
|
2022-06-07 21:14:35 +00:00
|
|
|
testId('welcome-text'))
|
|
|
|
),
|
2022-06-03 14:58:07 +00:00
|
|
|
makeCreateButtons(homeModel),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
function makeAnonIntro(homeModel: HomeModel) {
|
2022-12-06 13:57:29 +00:00
|
|
|
const signUp = cssLink({href: getLoginOrSignupUrl()}, t("Sign up"));
|
2022-06-03 14:58:07 +00:00
|
|
|
return [
|
2022-12-06 13:57:29 +00:00
|
|
|
css.docListHeader(t("Welcome to Grist!"), testId('welcome-title')),
|
|
|
|
cssIntroLine(t("Get started by exploring templates, or creating your first Grist document.")),
|
2023-01-31 16:35:46 +00:00
|
|
|
cssIntroLine(t("{{signUp}} to save your work. ", {signUp}),
|
2022-12-06 13:57:29 +00:00
|
|
|
(shouldHideUiElement('helpCenter') ? null : t("Visit our {{link}} to learn more.", { link: helpCenterLink() })),
|
2022-06-03 14:58:07 +00:00
|
|
|
testId('welcome-text')),
|
|
|
|
makeCreateButtons(homeModel),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
function helpCenterLink() {
|
2022-12-06 13:57:29 +00:00
|
|
|
return cssLink({href: commonUrls.help, target: '_blank'}, cssInlineIcon('Help'), t("Help Center"));
|
2022-06-03 14:58:07 +00:00
|
|
|
}
|
|
|
|
|
2022-09-07 09:52:40 +00:00
|
|
|
function buildButtons(homeModel: HomeModel, options: {
|
|
|
|
invite: boolean,
|
|
|
|
templates: boolean,
|
|
|
|
import: boolean,
|
|
|
|
empty: boolean,
|
|
|
|
}) {
|
2020-10-02 15:10:00 +00:00
|
|
|
return cssBtnGroup(
|
2022-09-07 09:52:40 +00:00
|
|
|
!options.invite ? null :
|
2022-12-06 13:57:29 +00:00
|
|
|
cssBtn(cssBtnIcon('Help'), t("Invite Team Members"), testId('intro-invite'),
|
2022-09-07 09:52:40 +00:00
|
|
|
cssButton.cls('-primary'),
|
|
|
|
dom.on('click', () => manageTeamUsersApp(homeModel.app)),
|
|
|
|
),
|
|
|
|
!options.templates ? null :
|
2022-12-06 13:57:29 +00:00
|
|
|
cssBtn(cssBtnIcon('FieldTable'), t("Browse Templates"), testId('intro-templates'),
|
2022-09-07 09:52:40 +00:00
|
|
|
cssButton.cls('-primary'),
|
|
|
|
dom.hide(shouldHideUiElement("templates")),
|
|
|
|
urlState().setLinkUrl({homePage: 'templates'}),
|
2022-06-03 14:58:07 +00:00
|
|
|
),
|
2022-09-07 09:52:40 +00:00
|
|
|
!options.import ? null :
|
2022-12-06 13:57:29 +00:00
|
|
|
cssBtn(cssBtnIcon('Import'), t("Import Document"), testId('intro-import-doc'),
|
2020-10-02 15:10:00 +00:00
|
|
|
dom.on('click', () => importDocAndOpen(homeModel)),
|
|
|
|
),
|
2022-09-07 09:52:40 +00:00
|
|
|
!options.empty ? null :
|
2022-12-06 13:57:29 +00:00
|
|
|
cssBtn(cssBtnIcon('Page'), t("Create Empty Document"), testId('intro-create-doc'),
|
2020-10-02 15:10:00 +00:00
|
|
|
dom.on('click', () => createDocAndOpen(homeModel)),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-09-07 09:52:40 +00:00
|
|
|
function makeCreateButtons(homeModel: HomeModel) {
|
|
|
|
const canManageTeam = homeModel.app.isTeamSite &&
|
|
|
|
roles.canEditAccess(homeModel.app.currentOrg?.access || null);
|
|
|
|
return buildButtons(homeModel, {
|
|
|
|
invite: canManageTeam,
|
|
|
|
templates: !canManageTeam,
|
|
|
|
import: true,
|
|
|
|
empty: true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-10-02 15:10:00 +00:00
|
|
|
const cssParagraph = styled(css.docBlock, `
|
2022-09-06 01:51:57 +00:00
|
|
|
color: ${theme.text};
|
2020-10-02 15:10:00 +00:00
|
|
|
line-height: 1.6;
|
|
|
|
`);
|
|
|
|
|
2022-06-03 14:58:07 +00:00
|
|
|
const cssIntroLine = styled(cssParagraph, `
|
|
|
|
font-size: ${vars.introFontSize};
|
|
|
|
margin-bottom: 8px;
|
|
|
|
`);
|
|
|
|
|
2020-10-02 15:10:00 +00:00
|
|
|
const cssBtnGroup = styled('div', `
|
|
|
|
display: inline-flex;
|
|
|
|
flex-direction: column;
|
|
|
|
align-items: stretch;
|
|
|
|
`);
|
|
|
|
|
|
|
|
const cssBtn = styled(bigBasicButton, `
|
2022-06-03 14:58:07 +00:00
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
2020-10-02 15:10:00 +00:00
|
|
|
margin-right: 16px;
|
|
|
|
margin-top: 16px;
|
|
|
|
text-align: left;
|
|
|
|
`);
|
|
|
|
|
|
|
|
const cssBtnIcon = styled(icon, `
|
|
|
|
margin-right: 8px;
|
|
|
|
`);
|
|
|
|
|
2022-06-03 14:58:07 +00:00
|
|
|
const cssInlineIcon = styled(icon, `
|
|
|
|
margin: -2px 4px 2px 4px;
|
|
|
|
`);
|