Skip to content

Commit

Permalink
Merge pull request #539 from VitNode/fix/rebuild_pages_script
Browse files Browse the repository at this point in the history
fix: Revalidate data after install vitnode
  • Loading branch information
aXenDeveloper authored Sep 29, 2024
2 parents faa2d9d + 21c27c2 commit 18f2008
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 28 deletions.
2 changes: 1 addition & 1 deletion packages/backend/scripts/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { spawn } from 'child_process';
// Function to run commands interactively with the ability to handle user input
const runInteractiveShellCommand = async (cmd: string, args: string[] = []) => {
return new Promise((resolve, reject) => {
const child = spawn(cmd, args, { stdio: 'inherit' });
const child = spawn(cmd, args, { stdio: 'inherit', shell: true });

child.on('error', error => {
reject(error);
Expand Down
16 changes: 11 additions & 5 deletions packages/frontend/src/hooks/core/sign/up/mutation-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import {
Core_Sessions__Sign_UpMutation,
Core_Sessions__Sign_UpMutationVariables,
} from '@/graphql/mutations/sessions/core_Sessions__sign_up.generated';
import { revalidatePath } from 'next/cache';

interface Args extends Core_Sessions__Sign_UpMutationVariables {
token: string;
}

export const mutationApi = async (variables: Args) => {
export const mutationApi = async (
variables: {
installPage?: boolean;
token: string;
} & Core_Sessions__Sign_UpMutationVariables,
) => {
try {
await fetcher<
Core_Sessions__Sign_UpMutation,
Expand All @@ -23,6 +25,10 @@ export const mutationApi = async (variables: Args) => {
'x-vitnode-captcha-token': variables.token,
},
});

if (variables.installPage) {
revalidatePath('/', 'layout');
}
} catch (error) {
const e = error as Error;

Expand Down
23 changes: 15 additions & 8 deletions packages/frontend/src/hooks/core/sign/up/use-sign-up-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { mutationApi } from './mutation-api';

export const nameRegex = /^(?!.* {2})[\p{L}\p{N}._@ -]*$/u;

export const useSignUpView = () => {
export const useSignUpView = ({ installPage }: { installPage?: boolean }) => {
const t = useTranslations('core');
const { setEmailSuccess } = useSignUp();
const { getTokenFromCaptcha, isReady } = useCaptcha();
Expand Down Expand Up @@ -39,12 +39,14 @@ export const useSignUpView = () => {
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%^&*()\-_=+{};:,<.>]).{8,}$/,
)
.default(''),
terms: z
.boolean()
.refine(value => value, {
message: t('sign_up.form.terms.empty'),
})
.default(false),
terms: installPage
? z.boolean().optional()
: z
.boolean()
.refine(value => value, {
message: t('sign_up.form.terms.empty'),
})
.default(false),
newsletter: z.boolean().default(false).optional(),
});

Expand All @@ -63,7 +65,12 @@ export const useSignUpView = () => {

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { terms, ...rest } = values;
const mutation = await mutationApi({ ...rest, token });
const mutation = await mutationApi({
...rest,
token,
installPage,
newsletter: installPage ? true : values.newsletter,
});

if (mutation?.error) {
if (mutation.error === 'CAPTCHA_FAILED') {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use client';

import { AutoForm } from '@/components/form/auto-form';
import { AutoFormCheckbox } from '@/components/form/fields/checkbox';
import {
AutoFormInput,
AutoFormInputProps,
Expand All @@ -16,7 +15,7 @@ import { useInstallVitnode } from '../../hooks/use-install-vitnode';

export const AccountInstallConfigsView = () => {
const t = useTranslations('core');
const { onSubmit, formSchema } = useSignUpView();
const { onSubmit, formSchema } = useSignUpView({ installPage: true });
const { setCurrentStep } = useInstallVitnode();

return (
Expand Down Expand Up @@ -90,17 +89,6 @@ export const AccountInstallConfigsView = () => {
);
},
},
{
id: 'terms',
label: t('sign_up.form.terms.label'),
component: AutoFormCheckbox,
},
{
id: 'newsletter',
label: t('sign_up.form.newsletter.label'),
description: t('sign_up.form.newsletter.desc'),
component: AutoFormCheckbox,
},
]}
formSchema={formSchema}
onSubmit={async (val, form) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { useTranslations } from 'next-intl';

export const FormSignUp = () => {
const t = useTranslations('core');
const { formSchema, onSubmit } = useSignUpView();
const { formSchema, onSubmit } = useSignUpView({});

return (
<AutoForm
Expand Down

0 comments on commit 18f2008

Please sign in to comment.