* added lockedSMS to future routes * add orgMigrations routes to future * correct metadata * small fix * add orgMigrations to future * Move components to client components * Remove tRPC element from edit user RSC * Get username for meta * Remove suspense query * Remove orgMigrations from app router * Type fix * Revert "Remove suspense query" This reverts commit eadd814f6e4a5d6856d9218342b7909c22fe62c6. * Handle suspenseQuery in app router * User edit page, fetch data server side * Update yarn.lock * Export getFixedT * Set PageWrapper as root layout for settings * Settings Layout accepts strings for shell heading * Add OOO to app router settings * Refactor layout for my-account pages * Remove instances of pages router from my-account * Refactor security pages * Add billing to app router * Add admin API link to layout * Add api keys page * Webhooks WIP * Refactor SettingsHeader to client component * Add webhook pages * Refactor API keys page * Add admin app page * Type fix * fix types * fix developer/webhooks/[id] param value type error * remove unnecessary code * do not pass t prop to CreateNewWebhookButton * fix type errors in webhook-edit-view * fix the remaining type errors * do not use prisma directly in generateMetadata * remove use client if unnecessary * Remove unused shell heading from SettingsLayoutAppDir * improve metadata * fix billing page * fix import in settings/teams * Use next `notFound()` * fix type check * fix type check * remove unused code * Fix calendar setting page * Separate settings pages into route groups * Refactor admin settings pages * Remove meta instance from billing page route * Update settings layoutAppDir * Refactor developer settings pages * Refactor out of office * Refactor my account settings * Refactor admin api page * Refactor security pages * Type fix * fix styling in settings layout --------- Co-authored-by: Somay Chauhan <somaychauhan98@gmail.com> Co-authored-by: Omar López <zomars@me.com> Co-authored-by: Benny Joo <sldisek783@gmail.com>
116 lines
3.4 KiB
TypeScript
116 lines
3.4 KiB
TypeScript
"use client";
|
|
|
|
import { zodResolver } from "@hookform/resolvers/zod";
|
|
import type { TFunction } from "next-i18next";
|
|
import { useState } from "react";
|
|
import { useForm } from "react-hook-form";
|
|
import z from "zod";
|
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
|
import { getStringAsNumberRequiredSchema } from "@calcom/prisma/zod-utils";
|
|
import { Button, TextField, Meta, showToast, Form } from "@calcom/ui";
|
|
|
|
import { getServerSideProps } from "@lib/settings/admin/orgMigrations/removeUserFromOrg/getServerSideProps";
|
|
|
|
import PageWrapper from "@components/PageWrapper";
|
|
|
|
import { getLayout } from "./_OrgMigrationLayout";
|
|
|
|
export { getServerSideProps };
|
|
|
|
function Wrapper({ children }: { children: React.ReactNode }) {
|
|
return (
|
|
<div>
|
|
<Meta
|
|
title="Organization Migration: Revert a user"
|
|
description="Reverts a migration of a user to an organization"
|
|
/>
|
|
{children}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
const enum State {
|
|
IDLE,
|
|
LOADING,
|
|
SUCCESS,
|
|
ERROR,
|
|
}
|
|
|
|
export const getFormSchema = (t: TFunction) =>
|
|
z.object({
|
|
userId: z.union([getStringAsNumberRequiredSchema(t), z.number()]),
|
|
targetOrgId: z.union([getStringAsNumberRequiredSchema(t), z.number()]),
|
|
});
|
|
|
|
export default function RemoveUserFromOrg() {
|
|
const [state, setState] = useState(State.IDLE);
|
|
const { t } = useLocale();
|
|
const formSchema = getFormSchema(t);
|
|
const form = useForm({
|
|
mode: "onSubmit",
|
|
resolver: zodResolver(formSchema),
|
|
});
|
|
const register = form.register;
|
|
return (
|
|
<Wrapper>
|
|
{/* Due to some reason auth from website doesn't work if /api endpoint is used. Spent a lot of time and in the end went with submitting data to the same page, because you can't do POST request to a page in Next.js, doing a GET request */}
|
|
<Form
|
|
form={form}
|
|
className="space-y-6"
|
|
handleSubmit={async (values) => {
|
|
setState(State.LOADING);
|
|
const res = await fetch(`/api/orgMigration/removeUserFromOrg`, {
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify(values),
|
|
});
|
|
let response = null;
|
|
try {
|
|
response = await res.json();
|
|
} catch (e) {
|
|
if (e instanceof Error) {
|
|
showToast(e.message, "error", 10000);
|
|
} else {
|
|
showToast(t("something_went_wrong"), "error", 10000);
|
|
}
|
|
setState(State.ERROR);
|
|
return;
|
|
}
|
|
if (res.status === 200) {
|
|
setState(State.SUCCESS);
|
|
showToast(response.message, "success", 10000);
|
|
} else {
|
|
setState(State.ERROR);
|
|
showToast(response.message, "error", 10000);
|
|
}
|
|
}}>
|
|
<div className="space-y-6">
|
|
<TextField
|
|
label="User ID"
|
|
{...register("userId")}
|
|
required
|
|
placeholder="Enter userId to remove from org"
|
|
/>
|
|
<TextField
|
|
className="mb-0"
|
|
label="Target Organization ID"
|
|
type="number"
|
|
required
|
|
{...register("targetOrgId")}
|
|
placeholder="Enter Target organization ID"
|
|
/>
|
|
</div>
|
|
<Button type="submit" loading={state === State.LOADING}>
|
|
Remove User from Org along with its teams
|
|
</Button>
|
|
</Form>
|
|
</Wrapper>
|
|
);
|
|
}
|
|
|
|
RemoveUserFromOrg.PageWrapper = PageWrapper;
|
|
RemoveUserFromOrg.getLayout = getLayout;
|