Restyle org name change section

This commit is contained in:
Tuan Dang
2023-06-27 18:48:26 +07:00
parent 5cd9f37fdf
commit 81c69d92b3
6 changed files with 92 additions and 98 deletions
@@ -3,9 +3,11 @@ import { Controller, useForm } from "react-hook-form";
import { yupResolver } from "@hookform/resolvers/yup"; import { yupResolver } from "@hookform/resolvers/yup";
import * as yup from "yup"; import * as yup from "yup";
import Button from "@app/components/basic/buttons/Button";
import { useNotificationContext } from "@app/components/context/Notifications/NotificationProvider"; import { useNotificationContext } from "@app/components/context/Notifications/NotificationProvider";
import { FormControl,Input } from "@app/components/v2"; import {
Button,
FormControl,
Input} from "@app/components/v2";
import { useOrganization } from "@app/context"; import { useOrganization } from "@app/context";
import { import {
useGetOrgBillingDetails, useGetOrgBillingDetails,
@@ -26,7 +28,7 @@ export const CompanyNameSection = () => {
resolver: yupResolver(schema) resolver: yupResolver(schema)
}); });
const { data } = useGetOrgBillingDetails(currentOrg?._id ?? ""); const { data } = useGetOrgBillingDetails(currentOrg?._id ?? "");
const updateOrgBillingDetails = useUpdateOrgBillingDetails(); const { mutateAsync, isLoading } = useUpdateOrgBillingDetails();
useEffect(() => { useEffect(() => {
if (data) { if (data) {
@@ -40,7 +42,7 @@ export const CompanyNameSection = () => {
try { try {
if (!currentOrg?._id) return; if (!currentOrg?._id) return;
if (name === "") return; if (name === "") return;
await updateOrgBillingDetails.mutateAsync({ await mutateAsync({
name, name,
organizationId: currentOrg._id organizationId: currentOrg._id
}); });
@@ -82,15 +84,13 @@ export const CompanyNameSection = () => {
name="name" name="name"
/> />
</div> </div>
<div className="inline-block"> <Button
<Button type="submit"
text="Save" colorSchema="secondary"
type="submit" isLoading={isLoading}
color="mineshaft" >
size="md" Save
onButtonPressed={() => console.log("Saved company name")} </Button>
/>
</div>
</form> </form>
); );
} }
@@ -3,9 +3,9 @@ import { Controller, useForm } from "react-hook-form";
import { yupResolver } from "@hookform/resolvers/yup"; import { yupResolver } from "@hookform/resolvers/yup";
import * as yup from "yup"; import * as yup from "yup";
import Button from "@app/components/basic/buttons/Button";
import { useNotificationContext } from "@app/components/context/Notifications/NotificationProvider"; import { useNotificationContext } from "@app/components/context/Notifications/NotificationProvider";
import { import {
Button,
FormControl, FormControl,
Input} from "@app/components/v2"; Input} from "@app/components/v2";
import { useOrganization } from "@app/context"; import { useOrganization } from "@app/context";
@@ -28,7 +28,7 @@ export const InvoiceEmailSection = () => {
resolver: yupResolver(schema) resolver: yupResolver(schema)
}); });
const { data } = useGetOrgBillingDetails(currentOrg?._id ?? ""); const { data } = useGetOrgBillingDetails(currentOrg?._id ?? "");
const updateOrgBillingDetails = useUpdateOrgBillingDetails(); const { mutateAsync, isLoading } = useUpdateOrgBillingDetails();
useEffect(() => { useEffect(() => {
if (data) { if (data) {
@@ -43,7 +43,7 @@ export const InvoiceEmailSection = () => {
if (!currentOrg?._id) return; if (!currentOrg?._id) return;
if (email === "") return; if (email === "") return;
await updateOrgBillingDetails.mutateAsync({ await mutateAsync({
email, email,
organizationId: currentOrg._id organizationId: currentOrg._id
}); });
@@ -85,15 +85,13 @@ export const InvoiceEmailSection = () => {
name="email" name="email"
/> />
</div> </div>
<div className="inline-block"> <Button
<Button type="submit"
text="Save" colorSchema="secondary"
type="submit" isLoading={isLoading}
color="mineshaft" >
size="md" Save
onButtonPressed={() => console.log("Saved email address")} </Button>
/>
</div>
</form> </form>
); );
} }
@@ -1,6 +1,10 @@
import { faPlus } from "@fortawesome/free-solid-svg-icons";
import Button from "@app/components/basic/buttons/Button"; import { faPlus } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import {
Button
} from "@app/components/v2";
import { useOrganization } from "@app/context"; import { useOrganization } from "@app/context";
import { useAddOrgPmtMethod } from "@app/hooks/api"; import { useAddOrgPmtMethod } from "@app/hooks/api";
@@ -8,11 +12,11 @@ import { PmtMethodsTable } from "./PmtMethodsTable";
export const PmtMethodsSection = () => { export const PmtMethodsSection = () => {
const { currentOrg } = useOrganization(); const { currentOrg } = useOrganization();
const addOrgPmtMethod = useAddOrgPmtMethod(); const { mutateAsync, isLoading } = useAddOrgPmtMethod();
const handleAddPmtMethodBtnClick = async () => { const handleAddPmtMethodBtnClick = async () => {
if (!currentOrg?._id) return; if (!currentOrg?._id) return;
const url = await addOrgPmtMethod.mutateAsync({ const url = await mutateAsync({
organizationId: currentOrg._id, organizationId: currentOrg._id,
success_url: window.location.href, success_url: window.location.href,
cancel_url: window.location.href cancel_url: window.location.href
@@ -27,16 +31,14 @@ export const PmtMethodsSection = () => {
<h2 className="text-xl font-semibold flex-1 text-white"> <h2 className="text-xl font-semibold flex-1 text-white">
Payment Methods Payment Methods
</h2> </h2>
<div className="inline-block"> <Button
<Button onClick={handleAddPmtMethodBtnClick}
text="Add method" colorSchema="secondary"
type="submit" isLoading={isLoading}
color="mineshaft" leftIcon={<FontAwesomeIcon icon={faPlus} />}
size="md" >
icon={faPlus} Add method
onButtonPressed={handleAddPmtMethodBtnClick} </Button>
/>
</div>
</div> </div>
<PmtMethodsTable /> <PmtMethodsTable />
</div> </div>
@@ -1,6 +1,9 @@
import { faPlus } from "@fortawesome/free-solid-svg-icons";
import Button from "@app/components/basic/buttons/Button"; import { faPlus } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { Button } from "@app/components/v2";
// import Button from "@app/components/basic/buttons/Button";
import { usePopUp } from "@app/hooks/usePopUp"; import { usePopUp } from "@app/hooks/usePopUp";
import { TaxIDModal } from "./TaxIDModal"; import { TaxIDModal } from "./TaxIDModal";
@@ -17,16 +20,13 @@ export const TaxIDSection = () => {
<h2 className="text-xl font-semibold flex-1 text-white"> <h2 className="text-xl font-semibold flex-1 text-white">
Tax ID Tax ID
</h2> </h2>
<div className="inline-block"> <Button
<Button onClick={() => handlePopUpOpen("addTaxID")}
text="Add Tax ID" colorSchema="secondary"
type="submit" leftIcon={<FontAwesomeIcon icon={faPlus} />}
color="mineshaft" >
size="md" Add method
icon={faPlus} </Button>
onButtonPressed={() => handlePopUpOpen("addTaxID")}
/>
</div>
</div> </div>
<TaxIDTable /> <TaxIDTable />
<TaxIDModal <TaxIDModal
@@ -18,7 +18,6 @@ import {
useGetOrgUsers, useGetOrgUsers,
useGetUserWorkspaceMemberships, useGetUserWorkspaceMemberships,
useGetUserWsKey, useGetUserWsKey,
useRenameOrg,
useUpdateOrgUserRole, useUpdateOrgUserRole,
useUploadWsKey useUploadWsKey
} from "@app/hooks/api"; } from "@app/hooks/api";
@@ -47,7 +46,7 @@ export const OrgSettingsPage = () => {
const { data: incidentContact, isLoading: IsIncidentContactLoading } = const { data: incidentContact, isLoading: IsIncidentContactLoading } =
useGetOrgIncidentContact(orgId); useGetOrgIncidentContact(orgId);
const renameOrg = useRenameOrg();
const removeUserOrgMembership = useDeleteOrgMembership(); const removeUserOrgMembership = useDeleteOrgMembership();
const addUserToOrg = useAddUserToOrg(); const addUserToOrg = useAddUserToOrg();
const updateOrgUserRole = useUpdateOrgUserRole(); const updateOrgUserRole = useUpdateOrgUserRole();
@@ -59,24 +58,6 @@ export const OrgSettingsPage = () => {
const isMoreUsersNotAllowed = subscription?.memberLimit ? (subscription.membersUsed >= subscription.memberLimit) : false; const isMoreUsersNotAllowed = subscription?.memberLimit ? (subscription.membersUsed >= subscription.memberLimit) : false;
const onRenameOrg = async (name: string) => {
if (!currentOrg?._id) return;
try {
await renameOrg.mutateAsync({ orgId: currentOrg?._id, newOrgName: name });
createNotification({
text: "Successfully renamed organization",
type: "success"
});
} catch (error) {
console.error(error);
createNotification({
text: "Failed to rename organization",
type: "error"
});
}
};
const onRemoveUserOrgMembership = async (membershipId: string) => { const onRemoveUserOrgMembership = async (membershipId: string) => {
if (!currentOrg?._id) return; if (!currentOrg?._id) return;
@@ -216,7 +197,7 @@ export const OrgSettingsPage = () => {
<p className="text-base font-normal text-gray-400">{t("settings.org.description")}</p> <p className="text-base font-normal text-gray-400">{t("settings.org.description")}</p>
</div> </div>
<div className="max-w-8xl ml-6 mr-6 flex flex-col text-mineshaft-50"> <div className="max-w-8xl ml-6 mr-6 flex flex-col text-mineshaft-50">
<OrgNameChangeSection orgName={currentOrg?.name} onOrgNameChange={onRenameOrg} /> <OrgNameChangeSection />
<div className="mb-6 w-full rounded-md bg-white/5 p-6"> <div className="mb-6 w-full rounded-md bg-white/5 p-6">
<p className="mr-4 mb-4 text-xl font-semibold text-white"> <p className="mr-4 mb-4 text-xl font-semibold text-white">
{t("section.members.org-members")} {t("section.members.org-members")}
@@ -1,17 +1,13 @@
import { useEffect } from "react"; import { useEffect } from "react";
import { Controller, useForm } from "react-hook-form"; import { Controller, useForm } from "react-hook-form";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { faCheck } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { yupResolver } from "@hookform/resolvers/yup"; import { yupResolver } from "@hookform/resolvers/yup";
import * as yup from "yup"; import * as yup from "yup";
import { useNotificationContext } from "@app/components/context/Notifications/NotificationProvider";
import { Button, FormControl, Input } from "@app/components/v2"; import { Button, FormControl, Input } from "@app/components/v2";
import { useOrganization } from "@app/context";
type Props = { import { useRenameOrg } from "@app/hooks/api";
orgName?: string;
onOrgNameChange: (name: string) => Promise<void>;
};
const formSchema = yup.object({ const formSchema = yup.object({
name: yup.string().required().label("Project Name") name: yup.string().required().label("Project Name")
@@ -19,33 +15,54 @@ const formSchema = yup.object({
type FormData = yup.InferType<typeof formSchema>; type FormData = yup.InferType<typeof formSchema>;
export const OrgNameChangeSection = ({ onOrgNameChange, orgName }: Props): JSX.Element => { export const OrgNameChangeSection = (): JSX.Element => {
const { t } = useTranslation();
const { currentOrg } = useOrganization();
const { createNotification } = useNotificationContext();
const { const {
handleSubmit, handleSubmit,
control, control,
reset, reset
formState: { isDirty, isSubmitting }
} = useForm<FormData>({ resolver: yupResolver(formSchema) }); } = useForm<FormData>({ resolver: yupResolver(formSchema) });
const { t } = useTranslation(); const { mutateAsync, isLoading } = useRenameOrg();
useEffect(() => { useEffect(() => {
reset({ name: orgName }); if (currentOrg) {
}, [orgName]); reset({ name: currentOrg.name });
}
}, [currentOrg]);
const onFormSubmit = async ({ name }: FormData) => { const onFormSubmit = async ({ name }: FormData) => {
await onOrgNameChange(name); try {
if (!currentOrg?._id) return;
if (name === "") return;
await mutateAsync({ orgId: currentOrg?._id, newOrgName: name });
createNotification({
text: "Successfully renamed organization",
type: "success"
});
} catch (error) {
console.error(error);
createNotification({
text: "Failed to rename organization",
type: "error"
});
}
}; };
return ( return (
<form onSubmit={handleSubmit(onFormSubmit)}> <form
<div className="mb-6 flex w-full flex-col items-start rounded-md bg-white/5 px-6 pb-6 pt-3"> onSubmit={handleSubmit(onFormSubmit)}
<p className="mb-4 mt-2 text-xl font-semibold">{t("common.display-name")}</p> className="p-4 bg-mineshaft-900 mb-6 max-w-screen-lg rounded-lg border border-mineshaft-600 "
<div className="mb-2 w-full max-w-lg"> >
<p className="text-xl font-semibold text-mineshaft-100 mb-8">{t("common.display-name")}</p>
<div className="mb-2 max-w-md">
<Controller <Controller
defaultValue="" defaultValue=""
render={({ field, fieldState: { error } }) => ( render={({ field, fieldState: { error } }) => (
<FormControl isError={Boolean(error)} errorText={error?.message}> <FormControl isError={Boolean(error)} errorText={error?.message}>
<Input placeholder="Type your org name" {...field} /> <Input placeholder="Acme Corp" {...field} />
</FormControl> </FormControl>
)} )}
control={control} control={control}
@@ -53,17 +70,13 @@ export const OrgNameChangeSection = ({ onOrgNameChange, orgName }: Props): JSX.E
/> />
</div> </div>
<Button <Button
isLoading={isSubmitting} isLoading={isLoading}
color="primary" color="primary"
variant="outline_bg" colorSchema="secondary"
size="sm"
type="submit" type="submit"
isDisabled={!isDirty || isSubmitting}
leftIcon={<FontAwesomeIcon icon={faCheck} />}
> >
{t("common.save-changes")} Save
</Button> </Button>
</div>
</form> </form>
); );
}; };