Skip to content

Commit

Permalink
fix(console-fb): using redirectWithFlash and remove throw
Browse files Browse the repository at this point in the history
  • Loading branch information
xmlking committed May 11, 2024
1 parent 7fe8240 commit 8d74252
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 23 deletions.
2 changes: 1 addition & 1 deletion apps/console-fb/src/lib/components/form/DeleteForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import { Logger } from '@spectacular/utils';
import { fail } from '@sveltejs/kit';
import type { GraphQLError } from 'graphql';
import { redirect } from 'sveltekit-flash-message/server';
import { redirect as redirectWithFlash } from 'sveltekit-flash-message/server';
import { setError, setMessage, superValidate } from 'sveltekit-superforms';
const log = new Logger('rule.action.server');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { fail } from '@sveltejs/kit';
import type { GraphQLError } from 'graphql';
import { redirect } from 'sveltekit-flash-message/server';
import { redirect as redirectWithFlash } from 'sveltekit-flash-message/server';
import { setError, setMessage, superValidate } from 'sveltekit-superforms';
import { zod } from 'sveltekit-superforms/adapters';
import { ToastLevel } from '$lib/components/toast';
Expand Down Expand Up @@ -32,7 +32,8 @@ export const actions = {
const dataCopy = cleanClone(form.data, { empty: 'null' });
log.debug('after cleanClone with null:', dataCopy);

const payload: devices_set_input = { // FIXME organization should not be changed.
const payload: devices_set_input = {
// FIXME organization should not be changed.
...(dataCopy.description && { description: dataCopy.description }),
...(dataCopy.annotations && { annotations: dataCopy.annotations }),
...(dataCopy.tags && { tags: dataCopy.tags })
Expand Down Expand Up @@ -60,6 +61,6 @@ export const actions = {
duration: 10000,
type: ToastLevel.Success
} as const;
throw redirect(302, '/dashboard/devices', message, event);
redirectWithFlash(302, '/dashboard/devices', message, event);
}
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { fail } from '@sveltejs/kit';
import type { GraphQLError } from 'graphql';
import { redirect } from 'sveltekit-flash-message/server';
import { redirect as redirectWithFlash } from 'sveltekit-flash-message/server';
import { setError, setMessage, superValidate } from 'sveltekit-superforms';
import { zod } from 'sveltekit-superforms/adapters';
import { ToastLevel } from '$lib/components/toast';
Expand All @@ -19,7 +19,7 @@ export const actions = {
const id = uuidSchema.parse(params.id);
const session = await locals.auth();
if (session?.user == undefined) {
throw redirect(307, `/auth/signin?callbackUrl=/dashboard/policies/${id}`);
redirectWithFlash(307, `/auth/signin?callbackUrl=/dashboard/policies/${id}`);
}

const form = await superValidate(request, zod(schema));
Expand All @@ -35,7 +35,7 @@ export const actions = {
/* eslint-disable @typescript-eslint/no-unused-vars */
const {
subjectDisplayName,
subjectId, /* eslint-disable-line */
subjectId /* eslint-disable-line */,
subjectSecondaryId,
subjectType,
ruleId,
Expand Down Expand Up @@ -97,6 +97,6 @@ export const actions = {
duration: 10000,
type: ToastLevel.Success
} as const;
throw redirect(302, '/dashboard/policies', message, event);
redirectWithFlash(302, '/dashboard/policies', message, event);
}
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { fail } from '@sveltejs/kit';
import type { GraphQLError } from 'graphql';
import { redirect } from 'sveltekit-flash-message/server';
import { redirect as redirectWithFlash } from 'sveltekit-flash-message/server';
import { setError, setMessage, superValidate } from 'sveltekit-superforms';
import { zod } from 'sveltekit-superforms/adapters';
import { Logger, cleanClone } from '@spectacular/utils';
Expand Down Expand Up @@ -91,6 +91,6 @@ export const actions = {
duration: 10000,
type: ToastLevel.Success
} as const;
throw redirect(302, '/dashboard/policies', message, event);
redirectWithFlash(302, '/dashboard/policies', message, event);
}
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { fail } from '@sveltejs/kit';
import type { GraphQLError } from 'graphql';
import { redirect } from 'sveltekit-flash-message/server';
import { redirect as redirectWithFlash } from 'sveltekit-flash-message/server';
import { setError, setMessage, superValidate } from 'sveltekit-superforms';
import { zod } from 'sveltekit-superforms/adapters';
import { ToastLevel } from '$lib/components/toast';
Expand Down Expand Up @@ -61,6 +61,6 @@ export const actions = {
duration: 10000,
type: ToastLevel.Success
} as const;
throw redirect(302, '/dashboard/pools', message, event);
redirectWithFlash(302, '/dashboard/pools', message, event);
}
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { RequestEvent } from '@sveltejs/kit';
import { fail } from '@sveltejs/kit';
import type { GraphQLError } from 'graphql';
import { redirect } from 'sveltekit-flash-message/server';
import { redirect as redirectWithFlash } from 'sveltekit-flash-message/server';
import { setError, setMessage, superValidate } from 'sveltekit-superforms';
import { zod } from 'sveltekit-superforms/adapters';
import { Logger, cleanClone } from '@spectacular/utils';
Expand Down Expand Up @@ -60,6 +60,6 @@ export const actions = {
duration: 10000,
type: ToastLevel.Success
} as const;
throw redirect(302, '/dashboard/pools', message, event);
redirectWithFlash(302, '/dashboard/pools', message, event);
}
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { fail } from '@sveltejs/kit';
import type { GraphQLError } from 'graphql';
import { redirect } from 'sveltekit-flash-message/server';
import { redirect as redirectWithFlash } from 'sveltekit-flash-message/server';
import { setError, setMessage, superValidate } from 'sveltekit-superforms';
import { zod } from 'sveltekit-superforms/adapters';
import { ToastLevel } from '$lib/components/toast';
Expand All @@ -19,7 +19,7 @@ export const actions = {
const id = uuidSchema.parse(params.id);
const session = await locals.auth();
if (session?.user == undefined) {
throw redirect(307, `/auth/signin?callbackUrl=/dashboard/rules/${id}`);
redirectWithFlash(307, `/auth/signin?callbackUrl=/dashboard/rules/${id}`);
}

const form = await superValidate(request, zod(schema));
Expand Down Expand Up @@ -65,6 +65,6 @@ export const actions = {
duration: 10000,
type: ToastLevel.Success
} as const;
throw redirect(302, '/dashboard/rules', message, event);
redirectWithFlash(302, '/dashboard/rules', message, event);
}
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { fail } from '@sveltejs/kit';
import type { GraphQLError } from 'graphql';
import { redirect } from 'sveltekit-flash-message/server';
import { redirect as redirectWithFlash } from 'sveltekit-flash-message/server';
import { setError, setMessage, superValidate } from 'sveltekit-superforms';
import { zod } from 'sveltekit-superforms/adapters';
import { Logger, cleanClone } from '@spectacular/utils';
Expand All @@ -17,7 +17,7 @@ export const actions = {
const { request, locals } = event;
const session = await locals.auth();
if (session?.user == undefined) {
throw redirect(307, '/auth/signin?callbackUrl=/dashboard/rules/create');
redirectWithFlash(307, '/auth/signin?callbackUrl=/dashboard/rules/create');
}

const form = await superValidate(request, zod(schema));
Expand Down Expand Up @@ -63,6 +63,6 @@ export const actions = {
duration: 10000,
type: ToastLevel.Success
} as const;
throw redirect(302, '/dashboard/rules', message, event);
redirectWithFlash(302, '/dashboard/rules', message, event);
}
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { fail } from '@sveltejs/kit';
import type { GraphQLError } from 'graphql';
import { redirect } from 'sveltekit-flash-message/server';
import { redirect as redirectWithFlash } from 'sveltekit-flash-message/server';
import { setError, setMessage, superValidate } from 'sveltekit-superforms';
import { zod } from 'sveltekit-superforms/adapters';
import { Logger } from '@spectacular/utils';
Expand All @@ -16,7 +16,7 @@ export const actions = {
const { request, locals } = event;
const session = await locals.auth();
if (session?.user == undefined) {
throw redirect(307, '/auth/signin?callbackUrl=/dashboard/rules');
redirectWithFlash(307, '/auth/signin?callbackUrl=/dashboard/rules');
}

const form = await superValidate(request, zod(schema));
Expand Down Expand Up @@ -47,6 +47,6 @@ export const actions = {
duration: 10000,
type: ToastLevel.Success
} as const;
throw redirect(302, '/dashboard/rules', message, event);
redirectWithFlash(302, '/dashboard/rules', message, event);
}
};
1 change: 1 addition & 0 deletions apps/console/src/app.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ declare global {
interface Session {
token?: string;
roles?: string | string[] | null;
// TODO: currentOrg?: string; // active user's org. default value is user's default_org
}
namespace Superforms {
type Message = Pick<ToastSettings, 'message' | 'hideDismiss' | 'timeout'> & {
Expand Down

0 comments on commit 8d74252

Please sign in to comment.