Skip to content

Commit

Permalink
Add permissions to mysql form (#2349)
Browse files Browse the repository at this point in the history
  • Loading branch information
alishakawaguchi authored Jul 25, 2024
1 parent 4d5626d commit c4d077f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import FormError from '@/components/FormError';
import { PasswordInput } from '@/components/PasswordComponent';
import Spinner from '@/components/Spinner';
import RequiredLabel from '@/components/labels/RequiredLabel';
import PermissionsDialog from '@/components/permissions/PermissionsDialog';
import { useAccount } from '@/components/providers/account-provider';
import {
Accordion,
Expand Down Expand Up @@ -49,10 +50,7 @@ import {
isConnectionNameAvailable,
updateConnection,
} from '@neosync/sdk/connectquery';
import {
CheckCircledIcon,
ExclamationTriangleIcon,
} from '@radix-ui/react-icons';
import { ExclamationTriangleIcon } from '@radix-ui/react-icons';
import { ReactElement, useState } from 'react';
import { Controller, useForm } from 'react-hook-form';
import { buildConnectionConfigMysql } from '../../util';
Expand Down Expand Up @@ -95,6 +93,8 @@ export default function MysqlForm(props: Props) {
CheckConnectionConfigResponse | undefined
>();
const [isValidating, setIsValidating] = useState<boolean>(false);
const [openPermissionDialog, setOpenPermissionDialog] =
useState<boolean>(false);

async function onSubmit(values: MysqlFormValues) {
try {
Expand Down Expand Up @@ -473,6 +473,16 @@ export default function MysqlForm(props: Props) {
</AccordionContent>
</AccordionItem>
</Accordion>
<PermissionsDialog
checkResponse={
validationResponse ?? new CheckConnectionConfigResponse({})
}
openPermissionDialog={openPermissionDialog}
setOpenPermissionDialog={setOpenPermissionDialog}
isValidating={isValidating}
connectionName={form.getValues('connectionName')}
connectionType="mysql"
/>
<div className="flex flex-row gap-3 justify-between">
<Button
variant="outline"
Expand All @@ -488,8 +498,8 @@ export default function MysqlForm(props: Props) {
}),
});

setIsValidating(false);
setValidationResponse(res);
setOpenPermissionDialog(!!res?.isConnected);
} catch (err) {
setValidationResponse(
new CheckConnectionConfigResponse({
Expand Down Expand Up @@ -523,9 +533,6 @@ export default function MysqlForm(props: Props) {
/>
</Button>
</div>
{validationResponse && validationResponse.isConnected && (
<SuccessAlert description={'Successfully connected!'} />
)}
{validationResponse && !validationResponse.isConnected && (
<ErrorAlert
title="Unable to connect"
Expand All @@ -539,24 +546,6 @@ export default function MysqlForm(props: Props) {
);
}

interface SuccessAlertProps {
description: string;
}

function SuccessAlert(props: SuccessAlertProps): ReactElement {
const { description } = props;
return (
<Alert variant="success">
<div className="flex flex-row items-center gap-2">
<CheckCircledIcon className="h-4 w-4 text-green-900 dark:text-green-400" />
<div className="font-normal text-green-900 dark:text-green-400">
{description}
</div>
</div>
</Alert>
);
}

interface ErrorAlertProps {
title: string;
description: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export default function ConnectionPage({ params }: PageProps) {

const showSubNav =
data?.connection?.connectionConfig?.config.case === 'pgConfig' ||
data?.connection?.connectionConfig?.config.case === 'mysqlConfig' ||
data?.connection?.connectionConfig?.config.case === 'dynamodbConfig' ||
data?.connection?.connectionConfig?.config.case === 'mongoConfig';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { PasswordInput } from '@/components/PasswordComponent';
import Spinner from '@/components/Spinner';
import RequiredLabel from '@/components/labels/RequiredLabel';
import { buildAccountOnboardingConfig } from '@/components/onboarding-checklist/OnboardingChecklist';
import PermissionsDialog from '@/components/permissions/PermissionsDialog';
import { useAccount } from '@/components/providers/account-provider';
import SkeletonForm from '@/components/skeleton/SkeletonForm';
import {
Expand Down Expand Up @@ -61,10 +62,7 @@ import {
isConnectionNameAvailable,
setAccountOnboardingConfig,
} from '@neosync/sdk/connectquery';
import {
CheckCircledIcon,
ExclamationTriangleIcon,
} from '@radix-ui/react-icons';
import { ExclamationTriangleIcon } from '@radix-ui/react-icons';
import { useQueryClient } from '@tanstack/react-query';
import { useRouter, useSearchParams } from 'next/navigation';
import { usePostHog } from 'posthog-js/react';
Expand Down Expand Up @@ -122,6 +120,8 @@ export default function MysqlForm() {
>();

const [isValidating, setIsValidating] = useState<boolean>(false);
const [openPermissionDialog, setOpenPermissionDialog] =
useState<boolean>(false);
const posthog = usePostHog();
const { mutateAsync: createMysqlConnection } = useMutation(createConnection);
const { mutateAsync: checkMysqlConnection } = useMutation(
Expand Down Expand Up @@ -702,6 +702,16 @@ the hook in the useEffect conditionally. This is used to retrieve the values for
</AccordionContent>
</AccordionItem>
</Accordion>
<PermissionsDialog
checkResponse={
validationResponse ?? new CheckConnectionConfigResponse({})
}
openPermissionDialog={openPermissionDialog}
setOpenPermissionDialog={setOpenPermissionDialog}
isValidating={isValidating}
connectionName={form.getValues('connectionName')}
connectionType="mysql"
/>
<div className="flex flex-row gap-3 justify-between">
<Button
variant="outline"
Expand All @@ -717,8 +727,8 @@ the hook in the useEffect conditionally. This is used to retrieve the values for
db: values.db,
}),
});
setIsValidating(false);
setValidationResponse(res);
setOpenPermissionDialog(!!res?.isConnected);
} catch (err) {
setValidationResponse(
new CheckConnectionConfigResponse({
Expand Down Expand Up @@ -760,32 +770,11 @@ the hook in the useEffect conditionally. This is used to retrieve the values for
}
/>
)}
{validationResponse && validationResponse.isConnected && (
<SuccessAlert description={'Successfully connected!'} />
)}
</form>
</Form>
);
}

interface SuccessAlertProps {
description: string;
}

function SuccessAlert(props: SuccessAlertProps): ReactElement {
const { description } = props;
return (
<Alert variant="success">
<div className="flex flex-row items-center gap-2">
<CheckCircledIcon className="h-4 w-4 text-green-900 dark:text-green-400" />
<div className="font-normal text-green-900 dark:text-green-400">
{description}
</div>
</div>
</Alert>
);
}

interface ErrorAlertProps {
title: string;
description: string;
Expand Down

0 comments on commit c4d077f

Please sign in to comment.