Skip to content

Commit

Permalink
devx ui changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nxtCoder19 committed Oct 7, 2024
1 parent 586b7ff commit 11e8ca5
Show file tree
Hide file tree
Showing 8 changed files with 225 additions and 102 deletions.
19 changes: 14 additions & 5 deletions src/apps/console/components/common-console-components.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,36 @@
import { ReactNode, useState } from 'react';
import { Button } from '~/components/atoms/button';
import TooltipV2 from '~/components/atoms/tooltipV2';
import { toast } from '~/components/molecule/toast';
import { cn } from '~/components/utils';
import { Check, Copy } from '~/console/components/icons';
import useClipboard from '~/root/lib/client/hooks/use-clipboard';
import { toast } from '~/components/molecule/toast';
import { Copy, Check } from '~/console/components/icons';
import { Truncate } from '~/root/lib/utils/common';
import TooltipV2 from '~/components/atoms/tooltipV2';

interface IDeleteContainer {
title: ReactNode;
children: ReactNode;
action: () => void;
content?: string;
disabled?: boolean;
}
export const DeleteContainer = ({
title,
children,
action,
content,
disabled = false,
}: IDeleteContainer) => {
return (
<div className="flex flex-col gap-3xl p-3xl rounded border border-border-critical bg-surface-basic-default shadow-button">
<div className="text-text-strong headingLg">{title}</div>
<div className="bodyMd text-text-default">{children}</div>
<Button onClick={action} content="Delete" variant="critical" />
<Button
onClick={action}
content={content || 'Delete'}
variant="critical"
disabled={disabled}
/>
</div>
);
};
Expand All @@ -48,7 +57,7 @@ export const Box = ({ children, title, className }: IBox) => {
<div
className={cn(
'rounded border border-border-default bg-surface-basic-default shadow-button p-3xl flex flex-col gap-3xl ',
className,
className
)}
>
<div className="text-text-strong headingLg">{title}</div>
Expand Down
54 changes: 49 additions & 5 deletions src/apps/console/routes/_main+/$account+/settings+/_layout.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import { Outlet, useOutletContext } from '@remix-run/react';
import { Outlet, useLoaderData, useOutletContext } from '@remix-run/react';
import SidebarLayout from '~/console/components/sidebar-layout';
import { GQLServerHandler } from '~/console/server/gql/saved-queries';
import { ensureAccountSet } from '~/console/server/utils/auth-utils';
import { useHandleFromMatches } from '~/root/lib/client/hooks/use-custom-matches';
import { IExtRemixCtx, LoaderResult } from '~/root/lib/types/common';
import { IAccountContext } from '../_layout';

const Settings = () => {
const rootContext = useOutletContext();
// const rootContext = useOutletContext();
const rootContext = useOutletContext<IAccountContext>();
const noLayout = useHandleFromMatches('noLayout', null);

const { teamMembers, currentUser } = useLoaderData();

if (noLayout) {
return <Outlet context={rootContext} />;
}
Expand All @@ -20,12 +27,49 @@ const Settings = () => {
// { label: 'VPN', value: 'vpn' },
]}
parentPath="/settings"
// headerTitle="Settings"
// headerActions={subNavAction.data}
// headerTitle="Settings"
// headerActions={subNavAction.data}
>
<Outlet context={rootContext} />
<Outlet
context={{
...rootContext,
teamMembers,
currentUser,
}}
/>
</SidebarLayout>
);
};

export const loader = async (ctx: IExtRemixCtx) => {
const { account } = ctx.params;
ensureAccountSet(ctx);
const { data, errors } = await GQLServerHandler(
ctx.request
).listMembershipsForAccount({
accountName: account,
});
if (errors) {
throw errors[0];
}

const { data: currentUser, errors: cErrors } = await GQLServerHandler(
ctx.request
).whoAmI({});

if (cErrors) {
throw cErrors[0];
}

return {
teamMembers: data,
currentUser,
};
};

export interface ISettingsContext extends IAccountContext {
teamMembers: LoaderResult<typeof loader>['teamMembers'];
currentUser: LoaderResult<typeof loader>['currentUser'];
}

export default Settings;
55 changes: 42 additions & 13 deletions src/apps/console/routes/_main+/$account+/settings+/general.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
import { Buildings, CopySimple } from '~/console/components/icons';
import { useNavigate, useOutletContext } from '@remix-run/react';
import { useEffect, useState } from 'react';
import { useEffect, useMemo, useState } from 'react';
import { Avatar } from '~/components/atoms/avatar';
import { Button } from '~/components/atoms/button';
import { TextInput } from '~/components/atoms/input';
import { toast } from '~/components/molecule/toast';
import { Buildings, CopySimple } from '~/console/components/icons';
import { parseName } from '~/console/server/r-utils/common';
import useClipboard from '~/root/lib/client/hooks/use-clipboard';
import useForm from '~/root/lib/client/hooks/use-form';
import { useUnsavedChanges } from '~/root/lib/client/hooks/use-unsaved-changes';
import { consoleBaseUrl } from '~/root/lib/configs/base-url.cjs';
import Yup from '~/root/lib/server/helpers/yup';
import { handleError } from '~/root/lib/utils/common';
import { parseName } from '~/console/server/r-utils/common';

import SecondarySubHeader from '~/console/components/secondary-sub-header';
import { useConsoleApi } from '~/console/server/gql/api-provider';
import { ConsoleApiType } from '~/console/server/gql/saved-queries';
import {
Box,
DeleteContainer,
} from '~/console/components/common-console-components';
import { IAccount } from '~/console/server/gql/queries/account-queries';
import DeleteDialog from '~/console/components/delete-dialog';
import SecondarySubHeader from '~/console/components/secondary-sub-header';
import { useConsoleApi } from '~/console/server/gql/api-provider';
import { IAccount } from '~/console/server/gql/queries/account-queries';
import { ConsoleApiType } from '~/console/server/gql/saved-queries';
import { useReload } from '~/root/lib/client/helpers/reloader';
import { IAccountContext } from '../_layout';
import { ISettingsContext } from './_layout';
// import SubNavAction from '../components/sub-nav-action';
// import { useConsoleApi } from '../server/gql/api-provider';
// import { IAccount } from '../server/gql/queries/access-queries';
Expand Down Expand Up @@ -59,6 +60,7 @@ export const updateAccount = async ({

const SettingGeneral = () => {
const { account } = useOutletContext<IAccountContext>();
const { teamMembers, currentUser } = useOutletContext<ISettingsContext>();
const [deleteAccount, setDeleteAccount] = useState(false);

const { setHasChanges, resetAndReload } = useUnsavedChanges();
Expand All @@ -72,6 +74,12 @@ const SettingGeneral = () => {
},
});

const isOwner = useMemo(() => {
if (!teamMembers || !currentUser) return false;
const owner = teamMembers.find((member) => member.role === 'account_owner');
return owner?.user?.email === currentUser?.email;
}, [teamMembers, currentUser]);

const { values, handleChange, submit, isLoading, resetValues } = useForm({
initialValues: {
displayName: account.displayName,
Expand Down Expand Up @@ -127,14 +135,15 @@ const SettingGeneral = () => {
<Box title="Profile">
<div className="flex flex-row items-center gap-3xl">
<Avatar size="lg" color="one" image={<Buildings />} />{' '}
<Button content="Upload photo" variant="basic" />
{/* <Button content="Upload photo" variant="basic" /> */}
</div>
<div className="flex flex-row gap-3xl">
<div className="flex-1">
<TextInput
label="Account name"
value={values.displayName}
onChange={handleChange('displayName')}
disabled={!isOwner}
/>
</div>
<div className="flex-1">
Expand Down Expand Up @@ -213,20 +222,40 @@ const SettingGeneral = () => {
</Box>

<DeleteContainer
title="Delete Account"
title="Disable Account"
action={async () => {
setDeleteAccount(true);
}}
content="Disable"
disabled={!isOwner}
>
Permanently remove your Account and all of its contents from the
Kloudlite platform. This action is not reversible — please continue
with caution.
For permanent delete or reverse your account and all of its contents
from the Kloudlite platform, please contact us at [email protected]
</DeleteContainer>
<DeleteDialog
resourceName={parseName(account)}
resourceType="account"
show={deleteAccount}
setShow={setDeleteAccount}
customMessages={{
action: 'Disable',
warning: (
<span>
Are you sure you want to disable &ldquo;{parseName(account)}
&rdquo;?
</span>
),
prompt: (
<>
<div className="bodyMd inline">Enter the account name</div>
<div className="bodyMd-semibold inline">
{' '}
{parseName(account)}{' '}
</div>
<div className="bodyMd inline">to continue:</div>
</>
),
}}
onSubmit={async () => {
try {
const { errors } = await api.deleteAccount({
Expand All @@ -237,7 +266,7 @@ const SettingGeneral = () => {
throw errors[0];
}
reload();
toast.success(`Account deleted successfully`);
toast.success(`Account disabled successfully`);
setDeleteAccount(false);
navigate(`/`);
} catch (err) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import { useOutletContext } from '@remix-run/react';
import { TextInput } from '~/components/atoms/input';
import SelectPrimitive from '~/components/atoms/select-primitive';
import Popup from '~/components/molecule/popup';
import { toast } from '~/components/molecule/toast';
import CommonPopupHandle from '~/console/components/common-popup-handle';
import { IDialogBase } from '~/console/components/types.d';
import {
IMemberType
} from '~/console/routes/_main+/$account+/settings+/user-management/user-access-resource';
import { useConsoleApi } from '~/console/server/gql/api-provider';
import { parseName } from '~/console/server/r-utils/common';
import useForm from '~/root/lib/client/hooks/use-form';
import Yup from '~/root/lib/server/helpers/yup';
import { handleError } from '~/root/lib/utils/common';
import { Github__Com___Kloudlite___Api___Apps___Iam___Types__Role as Role } from '~/root/src/generated/gql/server';
import { parseName } from '~/console/server/r-utils/common';
import CommonPopupHandle from '~/console/components/common-popup-handle';
import {
IMemberType,
mapRoleToDisplayName,
} from '~/console/routes/_main+/$account+/settings+/user-management/user-access-resource';
import { IAccountContext } from '../../_layout';

type IDialog = IDialogBase<IMemberType>;
Expand All @@ -40,7 +38,8 @@ const Root = (props: IDialog) => {
initialValues: isUpdate
? {
email: props?.data.email || '',
role: props?.data.role || 'account_member',
// role: props?.data.role || 'account_member',
role: 'account_member',
}
: {
email: '',
Expand Down Expand Up @@ -98,7 +97,7 @@ const Root = (props: IDialog) => {
)}
</div>

<SelectPrimitive.Root
{/* <SelectPrimitive.Root
label="Role"
value={values.role}
onChange={handleChange('role')}
Expand All @@ -113,7 +112,7 @@ const Root = (props: IDialog) => {
</SelectPrimitive.Option>
);
})}
</SelectPrimitive.Root>
</SelectPrimitive.Root> */}
</div>
</Popup.Content>
<Popup.Footer>
Expand Down
Loading

0 comments on commit 11e8ca5

Please sign in to comment.