Skip to content

Commit

Permalink
Merge upstream changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Sync Fork committed Nov 11, 2023
1 parent 5252fc4 commit 7b542c8
Show file tree
Hide file tree
Showing 30 changed files with 301 additions and 15 deletions.
8 changes: 8 additions & 0 deletions dashboard/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @nhost/dashboard

## 0.20.28

### Patch Changes

- 7c2c31082: feat: add support for users to delete their account
- @nhost/react-apollo@6.0.1
- @nhost/nextjs@1.13.40

## 0.20.27

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion dashboard/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nhost/dashboard",
"version": "0.20.27",
"version": "0.20.28",
"private": true,
"scripts": {
"preinstall": "npx only-allow pnpm",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
import { useDialog } from '@/components/common/DialogProvider';
import { SettingsContainer } from '@/components/layout/SettingsContainer';
import { Box } from '@/components/ui/v2/Box';
import { Button } from '@/components/ui/v2/Button';
import { Checkbox } from '@/components/ui/v2/Checkbox';
import { Text } from '@/components/ui/v2/Text';
import { getToastStyleProps } from '@/utils/constants/settings';
import {
useDeleteUserAccountMutation,
useGetAllWorkspacesAndProjectsQuery,
} from '@/utils/__generated__/graphql';
import { type ApolloError } from '@apollo/client';
import { useSignOut, useUserData } from '@nhost/nextjs';
import { useRouter } from 'next/router';
import { useState } from 'react';
import toast from 'react-hot-toast';
import { twMerge } from 'tailwind-merge';

function ConfirmDeleteAccountModal({
close,
onDelete,
}: {
onDelete?: () => Promise<any>;
close: () => void;
}) {
const [remove, setRemove] = useState(false);
const [loadingRemove, setLoadingRemove] = useState(false);

const user = useUserData();

const { data, loading } = useGetAllWorkspacesAndProjectsQuery({
skip: !user,
});

const userHasProjects =
!loading && data?.workspaces.some((workspace) => workspace.projects.length);

const userData = useUserData();

const [deleteUserAccount] = useDeleteUserAccountMutation({
variables: { id: userData?.id },
});

const onClickConfirm = async () => {
setLoadingRemove(true);

await toast.promise(
deleteUserAccount(),
{
loading: 'Deleting your account...',
success: `The account has been deleted successfully.`,
error: (arg: ApolloError) => {
// we need to get the internal error message from the GraphQL error
const { internal } = arg.graphQLErrors[0]?.extensions || {};
const { message } = (internal as Record<string, any>)?.error || {};

// we use the default Apollo error message if we can't find the
// internal error message
return (
message ||
arg.message ||
'An error occurred while deleting your account. Please try again.'
);
},
},
getToastStyleProps(),
);

onDelete?.();
close();
};

return (
<Box className={twMerge('w-full rounded-lg p-6 text-left')}>
<div className="grid grid-flow-row gap-1">
<Text variant="h3" component="h2">
Delete Account?
</Text>

{userHasProjects && (
<Text
variant="subtitle2"
className="font-bold"
sx={{ color: (theme) => `${theme.palette.error.main} !important` }}
>
You still have active projects. Please delete your projects before
proceeding with the account deletion.
</Text>
)}

<Box className="my-4">
<Checkbox
id="accept-1"
label={`I'm sure I want to delete my account`}
className="py-2"
checked={remove}
onChange={(_event, checked) => setRemove(checked)}
aria-label="Confirm Delete Project #1"
/>
</Box>

<div className="grid grid-flow-row gap-2">
<Button
color="error"
onClick={onClickConfirm}
disabled={userHasProjects}
loading={loadingRemove}
>
Delete
</Button>

<Button variant="outlined" color="secondary" onClick={close}>
Cancel
</Button>
</div>
</div>
</Box>
);
}

export default function DeleteAccount() {
const router = useRouter();
const { signOut } = useSignOut();

const { openDialog, closeDialog } = useDialog();

const onDelete = async () => {
await signOut();
await router.push('/signin');
};

const confirmDeleteAccount = async () => {
openDialog({
component: (
<ConfirmDeleteAccountModal close={closeDialog} onDelete={onDelete} />
),
});
};

return (
<SettingsContainer
title="Delete Account"
description="Please proceed with caution as the removal of your Personal Account and its contents from the Nhost platform is irreversible. This action will permanently delete your account and all associated data."
className="px-0"
slotProps={{
submitButton: { className: 'hidden' },
footer: { className: 'hidden' },
}}
>
<Box className="grid grid-flow-row border-t-1">
<Button
color="error"
className="mx-4 mt-4 justify-self-end"
onClick={confirmDeleteAccount}
>
Delete Personal Account
</Button>
</Box>
</SettingsContainer>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as DeleteAccount } from './DeleteAccount';
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mutation deleteUserAccount($id: uuid!) {
deleteUser(id: $id) {
__typename
}
}
3 changes: 3 additions & 0 deletions dashboard/src/pages/account/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Container } from '@/components/layout/Container';
import { RetryableErrorBoundary } from '@/components/presentational/RetryableErrorBoundary';
import { AccountSettingsLayout } from '@/features/account/settings/components/AccountSettingsLayout';
import { DeleteAccount } from '@/features/account/settings/components/DeleteAccount';
import { PasswordSettings } from '@/features/account/settings/components/PasswordSettings';
import { PATSettings } from '@/features/account/settings/components/PATSettings';
import type { ReactElement } from 'react';
Expand All @@ -18,6 +19,8 @@ export default function AccountSettingsPage() {
<RetryableErrorBoundary>
<PATSettings />
</RetryableErrorBoundary>

<DeleteAccount />
</Container>
);
}
Expand Down
40 changes: 40 additions & 0 deletions dashboard/src/utils/__generated__/graphql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @nhost/docs

## 0.7.1

### Patch Changes

- 1ee021b4a: remove custom domains from roadmap

## 0.7.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nhost/docs",
"version": "0.7.0",
"version": "0.7.1",
"private": true,
"scripts": {
"docusaurus": "docusaurus",
Expand Down
7 changes: 7 additions & 0 deletions examples/quickstarts/nextjs-server-components/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @nhost-examples/nextjs-server-components

## 0.1.1

### Patch Changes

- Updated dependencies [8b127fbb6]
- @nhost/nhost-js@2.2.18

## 0.1.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion examples/quickstarts/nextjs-server-components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nhost-examples/nextjs-server-components",
"version": "0.1.0",
"version": "0.1.1",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down
2 changes: 1 addition & 1 deletion examples/quickstarts/sveltekit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"postinstall": "pnpm add-nhost-js"
},
"devDependencies": {
"@nhost/nhost-js": "2.2.17",
"@nhost/nhost-js": "2.2.18",
"@playwright/test": "^1.31.0",
"@sveltejs/adapter-auto": "^2.0.0",
"@sveltejs/kit": "^1.5.0",
Expand Down
8 changes: 8 additions & 0 deletions examples/react-apollo/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @nhost-examples/react-apollo

## 0.1.16

### Patch Changes

- 6e61dce29: feat: add SignIn with Apple
- @nhost/react@2.1.1
- @nhost/react-apollo@6.0.1

## 0.1.15

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion examples/react-apollo/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nhost-examples/react-apollo",
"version": "0.1.15",
"version": "0.1.16",
"private": true,
"dependencies": {
"@apollo/client": "^3.7.14",
Expand Down
7 changes: 7 additions & 0 deletions integrations/apollo/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @nhost/apollo

## 5.2.22

### Patch Changes

- Updated dependencies [8b127fbb6]
- @nhost/nhost-js@2.2.18

## 5.2.21

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion integrations/apollo/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nhost/apollo",
"version": "5.2.21",
"version": "5.2.22",
"description": "Nhost Apollo Client library",
"license": "MIT",
"keywords": [
Expand Down
7 changes: 7 additions & 0 deletions integrations/react-apollo/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @nhost/react-apollo

## 6.0.1

### Patch Changes

- @nhost/apollo@5.2.22
- @nhost/react@2.1.1

## 6.0.0

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion integrations/react-apollo/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nhost/react-apollo",
"version": "6.0.0",
"version": "6.0.1",
"description": "Nhost React Apollo client",
"license": "MIT",
"keywords": [
Expand Down
6 changes: 6 additions & 0 deletions integrations/react-urql/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @nhost/react-urql

## 3.0.1

### Patch Changes

- @nhost/react@2.1.1

## 3.0.0

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion integrations/react-urql/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nhost/react-urql",
"version": "3.0.0",
"version": "3.0.1",
"description": "Nhost React URQL client",
"license": "MIT",
"keywords": [
Expand Down
Loading

0 comments on commit 7b542c8

Please sign in to comment.