Skip to content

Commit

Permalink
feat(Recipes): Add hasHostedOption to enable hosted & self hosted s…
Browse files Browse the repository at this point in the history
…ervices
  • Loading branch information
adlk committed Dec 15, 2017
1 parent 873957d commit 03610f2
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 7 deletions.
19 changes: 17 additions & 2 deletions src/components/settings/services/EditServiceForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ const messages = defineMessages({
id: 'settings.service.form.tabOnPremise',
defaultMessage: '!!!Self hosted ⭐️',
},
useHostedService: {
id: 'settings.service.form.useHostedService',
defaultMessage: '!!!Use the hosted {name} service.',
},
customUrlValidationError: {
id: 'settings.service.form.customUrlValidationError',
defaultMessage: '!!!Could not validate custom {name} server.',
Expand Down Expand Up @@ -108,7 +112,6 @@ export default class EditServiceForm extends Component {
this.props.form.submit({
onSuccess: async (form) => {
const values = form.values();

let isValid = true;

if (recipe.validateUrl && values.customUrl) {
Expand Down Expand Up @@ -166,6 +169,13 @@ export default class EditServiceForm extends Component {
/>
);

let activeTabIndex = 0;
if (recipe.hasHostedOption && service.team) {
activeTabIndex = 1;
} else if (recipe.hasHostedOption && service.customUrl) {
activeTabIndex = 2;
}

return (
<div className="settings__main">
<div className="settings__header">
Expand Down Expand Up @@ -198,8 +208,13 @@ export default class EditServiceForm extends Component {
<Input field={form.$('name')} focus />
{(recipe.hasTeamId || recipe.hasCustomUrl) && (
<Tabs
active={service.customUrl ? 1 : 0}
active={activeTabIndex}
>
{recipe.hasHostedOption && (
<TabItem title={recipe.name}>
{intl.formatMessage(messages.useHostedService, { name: recipe.name })}
</TabItem>
)}
{recipe.hasTeamId && (
<TabItem title={intl.formatMessage(messages.tabHosted)}>
<Input
Expand Down
11 changes: 11 additions & 0 deletions src/containers/settings/EditServiceScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,22 @@ export default class EditServiceScreen extends Component {
});
}

// More fine grained and use case specific validation rules
if (recipe.hasTeamId && recipe.hasCustomUrl) {
config.fields.team.validate = [oneRequired(['team', 'customUrl'])];
config.fields.customUrl.validate = [url, oneRequired(['team', 'customUrl'])];
}

// If a service can be hosted and has a teamId or customUrl
if (recipe.hasHostedOption && (recipe.hasTeamId || recipe.hasCustomUrl)) {
if (config.fields.team) {
config.fields.team.validate = [];
}
if (config.fields.customUrl) {
config.fields.customUrl.validate = [url];
}
}

if (recipe.hasIndirectMessages) {
Object.assign(config.fields, {
isIndirectMessageBadgeEnabled: {
Expand Down
2 changes: 2 additions & 0 deletions src/models/Recipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default class Recipe {
hasTeamId = false;
hasPredefinedUrl = false;
hasCustomUrl = false;
hasHostedOption = false;
urlInputPrefix = '';
urlInputSuffix = '';

Expand Down Expand Up @@ -45,6 +46,7 @@ export default class Recipe {
this.hasTeamId = data.config.hasTeamId || this.hasTeamId;
this.hasPredefinedUrl = data.config.hasPredefinedUrl || this.hasPredefinedUrl;
this.hasCustomUrl = data.config.hasCustomUrl || this.hasCustomUrl;
this.hasHostedOption = data.config.hasHostedOption || this.hasHostedOption;

this.urlInputPrefix = data.config.urlInputPrefix || this.urlInputPrefix;
this.urlInputSuffix = data.config.urlInputSuffix || this.urlInputSuffix;
Expand Down
12 changes: 7 additions & 5 deletions src/styles/content-tabs.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@
flex: 1;
// border: 1px solid $theme-gray-lightest;
color: $theme-gray-dark;
background: $theme-gray-lightest;
border-bottom: 1px solid $theme-gray-lighter;
box-shadow: inset 0px -3px 10px rgba(black, 0.05);
transition: all $theme-transition-time;
background: linear-gradient($theme-gray-lightest 80%, darken($theme-gray-lightest, 3%));
border-right: 1px solid $theme-gray-lighter;
transition: background $theme-transition-time;

&:last-of-type {
border-right: 0;
}

&.is-active {
background: $theme-brand-primary;
color: #FFF;
border-bottom: 1px solid $theme-brand-primary;
box-shadow: none;
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/styles/input.scss
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
padding: 8px;
// font-size: 18px;
color: $theme-gray;

&::placeholder {
color: lighten($theme-gray-light, 10%);
}
}

.franz-form__input-prefix,
Expand Down

0 comments on commit 03610f2

Please sign in to comment.