From 7b542c88fde368f6815b420ff812020aff96ac90 Mon Sep 17 00:00:00 2001 From: Sync Fork Date: Sat, 11 Nov 2023 00:03:34 +0000 Subject: [PATCH] Merge upstream changes --- dashboard/CHANGELOG.md | 8 + dashboard/package.json | 2 +- .../DeleteAccount/DeleteAccount.tsx | 161 ++++++++++++++++++ .../components/DeleteAccount/index.ts | 1 + .../settings/gql/deleteUserAccount.gql | 5 + dashboard/src/pages/account/index.tsx | 3 + dashboard/src/utils/__generated__/graphql.ts | 40 +++++ docs/CHANGELOG.md | 6 + docs/package.json | 2 +- .../nextjs-server-components/CHANGELOG.md | 7 + .../nextjs-server-components/package.json | 2 +- examples/quickstarts/sveltekit/package.json | 2 +- examples/react-apollo/CHANGELOG.md | 8 + examples/react-apollo/package.json | 2 +- integrations/apollo/CHANGELOG.md | 7 + integrations/apollo/package.json | 2 +- integrations/react-apollo/CHANGELOG.md | 7 + integrations/react-apollo/package.json | 2 +- integrations/react-urql/CHANGELOG.md | 6 + integrations/react-urql/package.json | 2 +- packages/nextjs/CHANGELOG.md | 6 + packages/nextjs/package.json | 2 +- packages/nhost-js/CHANGELOG.md | 6 + packages/nhost-js/package.json | 2 +- packages/nhost-js/src/index.ts | 1 + packages/nhost-js/src/utils/helpers.ts | 6 +- packages/react/CHANGELOG.md | 7 + packages/react/package.json | 2 +- packages/vue/CHANGELOG.md | 7 + packages/vue/package.json | 2 +- 30 files changed, 301 insertions(+), 15 deletions(-) create mode 100644 dashboard/src/features/account/settings/components/DeleteAccount/DeleteAccount.tsx create mode 100644 dashboard/src/features/account/settings/components/DeleteAccount/index.ts create mode 100644 dashboard/src/features/account/settings/gql/deleteUserAccount.gql diff --git a/dashboard/CHANGELOG.md b/dashboard/CHANGELOG.md index 54151ce02e..f94d2e467f 100644 --- a/dashboard/CHANGELOG.md +++ b/dashboard/CHANGELOG.md @@ -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 diff --git a/dashboard/package.json b/dashboard/package.json index 99452fd6e4..40f42f3c4b 100644 --- a/dashboard/package.json +++ b/dashboard/package.json @@ -1,6 +1,6 @@ { "name": "@nhost/dashboard", - "version": "0.20.27", + "version": "0.20.28", "private": true, "scripts": { "preinstall": "npx only-allow pnpm", diff --git a/dashboard/src/features/account/settings/components/DeleteAccount/DeleteAccount.tsx b/dashboard/src/features/account/settings/components/DeleteAccount/DeleteAccount.tsx new file mode 100644 index 0000000000..d3784dfbbd --- /dev/null +++ b/dashboard/src/features/account/settings/components/DeleteAccount/DeleteAccount.tsx @@ -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; + 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)?.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 ( + +
+ + Delete Account? + + + {userHasProjects && ( + `${theme.palette.error.main} !important` }} + > + You still have active projects. Please delete your projects before + proceeding with the account deletion. + + )} + + + setRemove(checked)} + aria-label="Confirm Delete Project #1" + /> + + +
+ + + +
+
+
+ ); +} + +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: ( + + ), + }); + }; + + return ( + + + + + + ); +} diff --git a/dashboard/src/features/account/settings/components/DeleteAccount/index.ts b/dashboard/src/features/account/settings/components/DeleteAccount/index.ts new file mode 100644 index 0000000000..1e5d672fc0 --- /dev/null +++ b/dashboard/src/features/account/settings/components/DeleteAccount/index.ts @@ -0,0 +1 @@ +export { default as DeleteAccount } from './DeleteAccount'; diff --git a/dashboard/src/features/account/settings/gql/deleteUserAccount.gql b/dashboard/src/features/account/settings/gql/deleteUserAccount.gql new file mode 100644 index 0000000000..5125799fea --- /dev/null +++ b/dashboard/src/features/account/settings/gql/deleteUserAccount.gql @@ -0,0 +1,5 @@ +mutation deleteUserAccount($id: uuid!) { + deleteUser(id: $id) { + __typename + } +} diff --git a/dashboard/src/pages/account/index.tsx b/dashboard/src/pages/account/index.tsx index 63338328f4..92a6548269 100644 --- a/dashboard/src/pages/account/index.tsx +++ b/dashboard/src/pages/account/index.tsx @@ -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'; @@ -18,6 +19,8 @@ export default function AccountSettingsPage() { + + ); } diff --git a/dashboard/src/utils/__generated__/graphql.ts b/dashboard/src/utils/__generated__/graphql.ts index 3352bd72d0..83f86e43f8 100644 --- a/dashboard/src/utils/__generated__/graphql.ts +++ b/dashboard/src/utils/__generated__/graphql.ts @@ -22196,6 +22196,13 @@ export type Workspaces_Updates = { where: Workspaces_Bool_Exp; }; +export type DeleteUserAccountMutationVariables = Exact<{ + id: Scalars['uuid']; +}>; + + +export type DeleteUserAccountMutation = { __typename?: 'mutation_root', deleteUser?: { __typename: 'users' } | null }; + export type GetPersonalAccessTokensQueryVariables = Exact<{ [key: string]: never; }>; @@ -23190,6 +23197,39 @@ export const GetWorkspaceMembersWorkspaceMemberInviteFragmentDoc = gql` memberType } `; +export const DeleteUserAccountDocument = gql` + mutation deleteUserAccount($id: uuid!) { + deleteUser(id: $id) { + __typename + } +} + `; +export type DeleteUserAccountMutationFn = Apollo.MutationFunction; + +/** + * __useDeleteUserAccountMutation__ + * + * To run a mutation, you first call `useDeleteUserAccountMutation` within a React component and pass it any options that fit your needs. + * When your component renders, `useDeleteUserAccountMutation` returns a tuple that includes: + * - A mutate function that you can call at any time to execute the mutation + * - An object with fields that represent the current status of the mutation's execution + * + * @param baseOptions options that will be passed into the mutation, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options-2; + * + * @example + * const [deleteUserAccountMutation, { data, loading, error }] = useDeleteUserAccountMutation({ + * variables: { + * id: // value for 'id' + * }, + * }); + */ +export function useDeleteUserAccountMutation(baseOptions?: Apollo.MutationHookOptions) { + const options = {...defaultOptions, ...baseOptions} + return Apollo.useMutation(DeleteUserAccountDocument, options); + } +export type DeleteUserAccountMutationHookResult = ReturnType; +export type DeleteUserAccountMutationResult = Apollo.MutationResult; +export type DeleteUserAccountMutationOptions = Apollo.BaseMutationOptions; export const GetPersonalAccessTokensDocument = gql` query GetPersonalAccessTokens { personalAccessTokens: authRefreshTokens( diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index caaef909ac..5d52d4f9c1 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,5 +1,11 @@ # @nhost/docs +## 0.7.1 + +### Patch Changes + +- 1ee021b4a: remove custom domains from roadmap + ## 0.7.0 ### Minor Changes diff --git a/docs/package.json b/docs/package.json index a077eafd74..3b7761476b 100644 --- a/docs/package.json +++ b/docs/package.json @@ -1,6 +1,6 @@ { "name": "@nhost/docs", - "version": "0.7.0", + "version": "0.7.1", "private": true, "scripts": { "docusaurus": "docusaurus", diff --git a/examples/quickstarts/nextjs-server-components/CHANGELOG.md b/examples/quickstarts/nextjs-server-components/CHANGELOG.md index 51010ea48f..923e83fcb3 100644 --- a/examples/quickstarts/nextjs-server-components/CHANGELOG.md +++ b/examples/quickstarts/nextjs-server-components/CHANGELOG.md @@ -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 diff --git a/examples/quickstarts/nextjs-server-components/package.json b/examples/quickstarts/nextjs-server-components/package.json index 99776e553b..f2d59ef988 100644 --- a/examples/quickstarts/nextjs-server-components/package.json +++ b/examples/quickstarts/nextjs-server-components/package.json @@ -1,6 +1,6 @@ { "name": "@nhost-examples/nextjs-server-components", - "version": "0.1.0", + "version": "0.1.1", "private": true, "scripts": { "dev": "next dev", diff --git a/examples/quickstarts/sveltekit/package.json b/examples/quickstarts/sveltekit/package.json index 8dc07274ea..61242cb5b3 100644 --- a/examples/quickstarts/sveltekit/package.json +++ b/examples/quickstarts/sveltekit/package.json @@ -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", diff --git a/examples/react-apollo/CHANGELOG.md b/examples/react-apollo/CHANGELOG.md index 9a334fc781..93870f93dc 100644 --- a/examples/react-apollo/CHANGELOG.md +++ b/examples/react-apollo/CHANGELOG.md @@ -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 diff --git a/examples/react-apollo/package.json b/examples/react-apollo/package.json index b214438350..64e5eaa04a 100644 --- a/examples/react-apollo/package.json +++ b/examples/react-apollo/package.json @@ -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", diff --git a/integrations/apollo/CHANGELOG.md b/integrations/apollo/CHANGELOG.md index f365b1347f..38fd9d61d2 100644 --- a/integrations/apollo/CHANGELOG.md +++ b/integrations/apollo/CHANGELOG.md @@ -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 diff --git a/integrations/apollo/package.json b/integrations/apollo/package.json index d04f168a8f..eca0653f0c 100644 --- a/integrations/apollo/package.json +++ b/integrations/apollo/package.json @@ -1,6 +1,6 @@ { "name": "@nhost/apollo", - "version": "5.2.21", + "version": "5.2.22", "description": "Nhost Apollo Client library", "license": "MIT", "keywords": [ diff --git a/integrations/react-apollo/CHANGELOG.md b/integrations/react-apollo/CHANGELOG.md index f0e6856eaf..33b6da6427 100644 --- a/integrations/react-apollo/CHANGELOG.md +++ b/integrations/react-apollo/CHANGELOG.md @@ -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 diff --git a/integrations/react-apollo/package.json b/integrations/react-apollo/package.json index 1954f35f8a..debc62535c 100644 --- a/integrations/react-apollo/package.json +++ b/integrations/react-apollo/package.json @@ -1,6 +1,6 @@ { "name": "@nhost/react-apollo", - "version": "6.0.0", + "version": "6.0.1", "description": "Nhost React Apollo client", "license": "MIT", "keywords": [ diff --git a/integrations/react-urql/CHANGELOG.md b/integrations/react-urql/CHANGELOG.md index 98c9a20f56..f712c87c25 100644 --- a/integrations/react-urql/CHANGELOG.md +++ b/integrations/react-urql/CHANGELOG.md @@ -1,5 +1,11 @@ # @nhost/react-urql +## 3.0.1 + +### Patch Changes + +- @nhost/react@2.1.1 + ## 3.0.0 ### Patch Changes diff --git a/integrations/react-urql/package.json b/integrations/react-urql/package.json index 668079e0fa..1a5d5743de 100644 --- a/integrations/react-urql/package.json +++ b/integrations/react-urql/package.json @@ -1,6 +1,6 @@ { "name": "@nhost/react-urql", - "version": "3.0.0", + "version": "3.0.1", "description": "Nhost React URQL client", "license": "MIT", "keywords": [ diff --git a/packages/nextjs/CHANGELOG.md b/packages/nextjs/CHANGELOG.md index 80ba947433..c8edb8d2e1 100644 --- a/packages/nextjs/CHANGELOG.md +++ b/packages/nextjs/CHANGELOG.md @@ -1,5 +1,11 @@ # @nhost/nextjs +## 1.13.40 + +### Patch Changes + +- @nhost/react@2.1.1 + ## 1.13.39 ### Patch Changes diff --git a/packages/nextjs/package.json b/packages/nextjs/package.json index 56f9cc8d85..896aca1bd6 100644 --- a/packages/nextjs/package.json +++ b/packages/nextjs/package.json @@ -1,6 +1,6 @@ { "name": "@nhost/nextjs", - "version": "1.13.39", + "version": "1.13.40", "description": "Nhost NextJS library", "license": "MIT", "keywords": [ diff --git a/packages/nhost-js/CHANGELOG.md b/packages/nhost-js/CHANGELOG.md index 2ec5c56d0a..b717e33506 100644 --- a/packages/nhost-js/CHANGELOG.md +++ b/packages/nhost-js/CHANGELOG.md @@ -1,5 +1,11 @@ # @nhost/nhost-js +## 2.2.18 + +### Patch Changes + +- 8b127fbb6: feat: export `urlFromSubdomain` helper + ## 2.2.17 ### Patch Changes diff --git a/packages/nhost-js/package.json b/packages/nhost-js/package.json index 75ea8cc6b1..74d592cd42 100644 --- a/packages/nhost-js/package.json +++ b/packages/nhost-js/package.json @@ -1,6 +1,6 @@ { "name": "@nhost/nhost-js", - "version": "2.2.17", + "version": "2.2.18", "description": "Nhost JavaScript SDK", "license": "MIT", "keywords": [ diff --git a/packages/nhost-js/src/index.ts b/packages/nhost-js/src/index.ts index e38238dbc1..b9ce01366f 100644 --- a/packages/nhost-js/src/index.ts +++ b/packages/nhost-js/src/index.ts @@ -1,4 +1,5 @@ export * from '@nhost/hasura-auth-js' export * from '@nhost/hasura-storage-js' export * from './clients' +export { urlFromSubdomain } from './utils/helpers' export * from './utils/types' diff --git a/packages/nhost-js/src/utils/helpers.ts b/packages/nhost-js/src/utils/helpers.ts index c6ba2b0545..dc45a8fd04 100644 --- a/packages/nhost-js/src/utils/helpers.ts +++ b/packages/nhost-js/src/utils/helpers.ts @@ -5,9 +5,9 @@ export const LOCALHOST_REGEX = /^((?http[s]?):\/\/)?(?(localhost|local))(:(?(\d+|__\w+__)))?$/ /** - * `backendUrl` should now be used only when self-hosting - * `subdomain` and `region` should be used instead when using the Nhost platform - * ` + * \`backendUrl\` should now be used only when self-hosting + * \`subdomain\` and `region` should be used instead when using the Nhost platform + * * @param backendOrSubdomain * @param service * @returns diff --git a/packages/react/CHANGELOG.md b/packages/react/CHANGELOG.md index 55b2dd013f..d6867599ee 100644 --- a/packages/react/CHANGELOG.md +++ b/packages/react/CHANGELOG.md @@ -1,5 +1,12 @@ # @nhost/react +## 2.1.1 + +### Patch Changes + +- Updated dependencies [8b127fbb6] + - @nhost/nhost-js@2.2.18 + ## 2.1.0 ### Minor Changes diff --git a/packages/react/package.json b/packages/react/package.json index 053a7506d6..0f50196e35 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -1,6 +1,6 @@ { "name": "@nhost/react", - "version": "2.1.0", + "version": "2.1.1", "description": "Nhost React library", "license": "MIT", "keywords": [ diff --git a/packages/vue/CHANGELOG.md b/packages/vue/CHANGELOG.md index 02fb48f23a..46e4f76ad1 100644 --- a/packages/vue/CHANGELOG.md +++ b/packages/vue/CHANGELOG.md @@ -1,5 +1,12 @@ # @nhost/vue +## 1.14.1 + +### Patch Changes + +- Updated dependencies [8b127fbb6] + - @nhost/nhost-js@2.2.18 + ## 1.14.0 ### Minor Changes diff --git a/packages/vue/package.json b/packages/vue/package.json index a3cf743b52..512298b7ee 100644 --- a/packages/vue/package.json +++ b/packages/vue/package.json @@ -1,6 +1,6 @@ { "name": "@nhost/vue", - "version": "1.14.0", + "version": "1.14.1", "description": "Nhost Vue library", "license": "MIT", "keywords": [