ToolJet/frontend/src/ManageSSO/Google.jsx
Kavin Venkatachalam 7f702c1d6b
[Feature]: Added Localisation (#3746)
* Added localisation

* Closed modal after language selection

* updated transaltaion setup

* Updated language tooltip

* Added fallback language support

* Adding english library resource for translation (#3844)

* Adding English dictionary for the widget lists in the inspector

* added leftSideBar object in en.json and implemented it for leftSidebar icon text

* renamed leftSideBar to leftSidebar and added resources for tip in the left side bar

* added english translation resources for leftsidebar debugger

* added english language resources for the global settings

* added english language resources for data sources in left sidebar

* added english language resources for the share button and share modal in the editor

* added english language resources for release button, manageOrgUsers, appVersionManager

* added english language resources for Queries and Please select a widget to inspect in the editor

* added english language resources for data source list , data source manager, and query manager(partially)

* added english language resources for queryManager, transformation, preview

* added english language resources for dark mode toggle in the headers inside homepage

* added fallback message for dark mode toggle

* added resources for language change in the headers inside homepage

* added resources for notification center in the header inside homepage

* added resources for organization and manage users components in header inside homepage

* added resources in manageGroupPermission

* added resources for manageGroupPermissionsResources component

* added resources for manageSSO and generalSettings components

* added resources for google sso

* added resources for github sso

* added resources for environment variables in manageSSO

* added resources for profile and setting page

* added resources for app card and app card menu

* added resources for folder section and app list in homepage

* added resources for header section in the homepage

* added resources for pagination in homepage

* added resources for modals in the homepage

* added resources for blank page

* added resources for login page

* added resources for forgot password page

* added resources for sign up page

* added resources for onBoarding component

* added resources for reset password page

* deleted duplicate key for readDocumentation

* deleted duplicate key for cancel in en.json and added translation for cancel at few places

* removing duplicate copy of save key in en.json

* added translation for CommentActions.jsx components

* deleted duplicate copy of search key in en.json and added resources for create and search queries , select keys

* fix typo errors

* fixed typo errors

* shorten the key for loginAndSignUpAndForgotPassword to loginSignupPage in en.json file and related files

* shorten the key noLoginMethodsEnabledForThisWorkspace to noLoginMethodsEnabled

* shorten the key pleaseCheckYourEmailForConfirmationLink to emailConfirmLink

* shorten the key dontHaveAccountYet to dontHaveAccount

* shorten keys from loginSignupPage key in en.json

* shorten keys of shareModal nested object in en.json

* shorten the key in appVersionManager nested object

* shorten the keys for queryManager nested object in the en.json

* delete duplicate copy of environmentVar and shorten manageEnvironmentVariables,environmentVariables

* shorten keys in the organization nested object

* shorten keys in the homePage nested object in en.json file

* added inspector and eventManager empty object

* added resources to RedirectSSO component

* added resources for OAuth2

* added resources for TemplateCard.jsx

* added resources for TemplateLibraryModal.jsx

* added resources for ConfirmationPage.jsx

* added resources for ConfirmationPage component

* removed translation in App.jsx file

* added resources for Slack.jsx

* added resources for GoogleSheets.jsx

* added resources for CodeBuilder.jsx

* added resources for CommentBody and CommentFooter

* added resources for TestConnection component

* added resources for AllignButton.jsx

* added resources for Openapi and Stripe components

* added resources for ErrorBoundary

* added resources for Viewer.jsx

* Translation for widgets, table

Co-authored-by: Kavin Venkatachalam <kavin.saratha@gmail.com>

* Commented Language selection

* Fixed typos

* Updated fr.json file

Co-authored-by: Manish Kushare <kushare.manish9@gmail.com>
2022-09-14 13:34:49 +05:30

143 lines
5 KiB
JavaScript

import React, { useState } from 'react';
import { organizationService } from '@/_services';
import { toast } from 'react-hot-toast';
import { copyToClipboard } from '@/_helpers/appUtils';
import { useTranslation } from 'react-i18next';
export function Google({ settings, updateData }) {
const [enabled, setEnabled] = useState(settings?.enabled || false);
const [clientId, setClientId] = useState(settings?.configs?.client_id || '');
const [isSaving, setSaving] = useState(false);
const [configId, setConfigId] = useState(settings?.id);
const { t } = useTranslation();
const reset = () => {
setClientId(settings?.configs?.client_id || '');
};
const copyFunction = (input) => {
let text = document.getElementById(input).innerHTML;
copyToClipboard(text);
};
const saveSettings = () => {
setSaving(true);
organizationService.editOrganizationConfigs({ type: 'google', configs: { clientId } }).then(
(data) => {
setSaving(false);
data.id && setConfigId(data.id);
updateData('google', { id: data.id, configs: { client_id: clientId } });
toast.success('updated SSO configurations', {
position: 'top-center',
});
},
() => {
setSaving(false);
toast.error('Error while saving SSO configurations', {
position: 'top-center',
});
}
);
};
const changeStatus = () => {
setSaving(true);
organizationService.editOrganizationConfigs({ type: 'google', enabled: !enabled }).then(
(data) => {
setSaving(false);
const enabled_tmp = !enabled;
setEnabled(enabled_tmp);
data.id && setConfigId(data.id);
updateData('google', { id: data.id, enabled: enabled_tmp });
toast.success(`${enabled_tmp ? 'Enabled' : 'Disabled'} Google SSO`, {
position: 'top-center',
});
},
() => {
setSaving(false);
toast.error('Error while saving SSO configurations', {
position: 'top-center',
});
}
);
};
return (
<div className="card">
<div className="card-header">
<div className="d-flex justify-content-between title-with-toggle">
<div className="card-title" data-cy="card-title">
{t('header.organization.menus.manageSSO.google.title', 'Google')}
<span className={`badge bg-${enabled ? 'green' : 'grey'} ms-1`} data-cy="status-label">
{enabled
? t('header.organization.menus.manageSSO.google.enabled', 'Enabled')
: t('header.organization.menus.manageSSO.google.disabled', 'Disabled')}
</span>
</div>
<div>
<label className="form-check form-switch">
<input
className="form-check-input"
type="checkbox"
checked={enabled}
onChange={changeStatus}
data-cy="form-check-input"
/>
</label>
</div>
</div>
</div>
<div className="card-body">
<form noValidate>
<div className="form-group mb-3">
<label className="form-label" data-cy="client-id-label">
{t('header.organization.menus.manageSSO.google.clientId', 'Client Id')}
</label>
<div>
<input
type="text"
className="form-control"
placeholder={t('header.organization.menus.manageSSO.google.enterClientId', 'Enter Client Id')}
value={clientId}
onChange={(e) => setClientId(e.target.value)}
data-cy="client-id-input"
/>
</div>
</div>
{configId && (
<div className="form-group mb-3">
<label className="form-label" data-cy="redirect-url-label">
{t('header.organization.menus.manageSSO.google.redirectUrl', 'Redirect URL')}
</label>
<div className="flexer-sso-input form-control">
<p
data-cy="redirect-url"
id="redirect-url"
>{`${window.location.protocol}//${window.location.host}/sso/google/${configId}`}</p>
<img
onClick={() => copyFunction('redirect-url')}
src={`assets/images/icons/copy-dark.svg`}
width="22"
height="22"
className="sso-copy"
/>
</div>
</div>
)}
<div className="form-footer">
<button type="button" className="btn btn-light mr-2" onClick={reset} data-cy="cancel-button">
{t('globals.cancel', 'Cancel')}
</button>
<button
type="button"
className={`btn mx-2 btn-primary ${isSaving ? 'btn-loading' : ''}`}
disabled={isSaving}
onClick={saveSettings}
data-cy="save-button"
>
{t('globals.save', 'Save')}
</button>
</div>
</form>
</div>
</div>
);
}