Files
cal.diy/packages/features/ee/organizations/components/AboutOrganizationForm.tsx
T
+2 cc99e1697b fix: Creating team and preview URL fixes [CAL-1997] [CAL-1998] (#9648)
* Creating team and preview URL fixes

* Renamed function in tests too

* fix: Signup from org wizard invitation and other tweaks [CAL-1973] [CAL-1993] [CAL-1994] (#9693)

* Fixing signup from org invitation and other tweaks

* feat:  Organizations no middleware rewrite (#9548)

Co-authored-by: Leo Giovanetti <[email protected]>
Co-authored-by: zomars <[email protected]>
Co-authored-by: Peer Richelsen <[email protected]>

* Revert "fix: redirect to 404 page for invalid email verification token" (#9703)

* New Crowdin translations by Github Action

* refactor: Skip license checks for development (#9375)

* Allow closing the embed on clicking the black transparent area (#9706)

* New Crowdin translations by Github Action

* perf: [CAL-1928] Deduplicate eventTypes.getByViewer query (#9700)

Co-authored-by: alannnc <[email protected]>
Co-authored-by: Udit Takkar <[email protected]>

* perf: Remove useless data on EvenTypes getByViewer endpoint (#9704)

* feat: [CAL-910] Pre-select country for phone number (CALCOM-5759) (#9526)

Co-authored-by: gitstart-calcom <[email protected]>

* Fix settings layout + org headings (#9712)

* Simplifying prop

* Removing restriction to choose username

* Formatting

---------

Co-authored-by: Efraín Rochín <[email protected]>
Co-authored-by: zomars <[email protected]>
Co-authored-by: Peer Richelsen <[email protected]>
Co-authored-by: Crowdin Bot <[email protected]>
Co-authored-by: alannnc <[email protected]>
Co-authored-by: Hariom Balhara <[email protected]>
Co-authored-by: Afzal Sayed <[email protected]>
Co-authored-by: Udit Takkar <[email protected]>
Co-authored-by: GitStart-Cal.com <[email protected]>
Co-authored-by: gitstart-calcom <[email protected]>
Co-authored-by: sean-brydon <[email protected]>

* Fix conditional before hook

* Fix lints

---------

Co-authored-by: Udit Takkar <[email protected]>
Co-authored-by: Efraín Rochín <[email protected]>
Co-authored-by: zomars <[email protected]>
Co-authored-by: Peer Richelsen <[email protected]>
Co-authored-by: Crowdin Bot <[email protected]>
Co-authored-by: alannnc <[email protected]>
Co-authored-by: Hariom Balhara <[email protected]>
Co-authored-by: Afzal Sayed <[email protected]>
Co-authored-by: GitStart-Cal.com <[email protected]>
Co-authored-by: gitstart-calcom <[email protected]>
Co-authored-by: sean-brydon <[email protected]>
2023-07-03 08:06:12 +00:00

124 lines
3.7 KiB
TypeScript

import { useRouter } from "next/router";
import { useState } from "react";
import { Controller, useForm } from "react-hook-form";
import z from "zod";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { trpc } from "@calcom/trpc/react";
import { Avatar, Button, Form, ImageUploader, Alert, Label, TextAreaField } from "@calcom/ui";
import { ArrowRight, Plus } from "@calcom/ui/components/icon";
const querySchema = z.object({
id: z.string(),
});
export const AboutOrganizationForm = () => {
const { t } = useLocale();
const router = useRouter();
const { id: orgId } = querySchema.parse(router.query);
const [serverErrorMessage, setServerErrorMessage] = useState<string | null>(null);
const [image, setImage] = useState("");
const aboutOrganizationFormMethods = useForm<{
logo: string;
bio: string;
}>();
const updateOrganizationMutation = trpc.viewer.organizations.update.useMutation({
onSuccess: (data) => {
if (data.update) {
router.push(`/settings/organizations/${orgId}/onboard-admins`);
}
},
onError: (err) => {
setServerErrorMessage(err.message);
},
});
return (
<>
<Form
form={aboutOrganizationFormMethods}
className="space-y-5"
handleSubmit={(v) => {
if (!updateOrganizationMutation.isLoading) {
setServerErrorMessage(null);
updateOrganizationMutation.mutate({ ...v, orgId });
}
}}>
{serverErrorMessage && (
<div>
<Alert severity="error" message={serverErrorMessage} />
</div>
)}
<div>
<Controller
control={aboutOrganizationFormMethods.control}
name="logo"
render={() => (
<>
<Label>{t("organization_logo")}</Label>
<div className="flex items-center">
<Avatar
alt=""
fallback={<Plus className="text-subtle h-6 w-6" />}
asChild
className="items-center"
imageSrc={image}
size="lg"
/>
<div className="ms-4">
<ImageUploader
target="avatar"
id="avatar-upload"
buttonMsg={t("upload")}
handleAvatarChange={(newAvatar: string) => {
setImage(newAvatar);
aboutOrganizationFormMethods.setValue("logo", newAvatar);
}}
imageSrc={image}
/>
</div>
</div>
</>
)}
/>
</div>
<div>
<Controller
control={aboutOrganizationFormMethods.control}
name="bio"
render={({ field: { value } }) => (
<>
<TextAreaField
name="about"
defaultValue={value}
onChange={(e) => {
aboutOrganizationFormMethods.setValue("bio", e?.target.value);
}}
/>
<p className="text-subtle text-sm">{t("organization_about_description")}</p>
</>
)}
/>
</div>
<div className="flex">
<Button
disabled={
aboutOrganizationFormMethods.formState.isSubmitting || updateOrganizationMutation.isLoading
}
color="primary"
EndIcon={ArrowRight}
type="submit"
className="w-full justify-center">
{t("continue")}
</Button>
</div>
</Form>
</>
);
};