* storybook v2 init * Merge config into storybook vite build * Remove path * Storybook config tweaks * Added styles and settings for storybook v2, and started working on button documentation and examples. * Badges + flex wrap on mobile * Breadcrumbs+button+avatar * Checkbox * Input + moving files around * WIP table * WIP table grid * Replaced imports for new components. * Added first steps for varianttable. * Small alignment fix. * Custom Args Table - With scrollbar * Adding table to components that need it + darkmode * Add intro * Fix types * Remove V1 storybook and replace with V2 * Fix badge type error * Fixed storybook dependencies * Added cover image to storybook * Remove vita from ts config, we dont use vite. * Fixed button import. * Explained postcss pseudo plugin. * Fixed badge import. * Add Avatar Stories * ButtonGroup Stories * Fixed imports * Add checkbox stories * Add exports for differnt types of inputs * Fix form and text area input * Fix mass import errors Co-authored-by: Jeroen Reumkens <hello@jeroenreumkens.nl> Co-authored-by: Alex van Andel <me@alexvanandel.com>
89 lines
2.7 KiB
TypeScript
89 lines
2.7 KiB
TypeScript
import { ArrowRightIcon } from "@heroicons/react/solid";
|
|
import { useRouter } from "next/router";
|
|
import { useForm } from "react-hook-form";
|
|
|
|
import { Schedule } from "@calcom/features/schedules";
|
|
import { DEFAULT_SCHEDULE } from "@calcom/lib/availability";
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
|
import { trpc, TRPCClientErrorLike } from "@calcom/trpc/react";
|
|
import { AppRouter } from "@calcom/trpc/server/routers/_app";
|
|
import { Button } from "@calcom/ui/components/button";
|
|
import { Form } from "@calcom/ui/form/fields";
|
|
|
|
interface ISetupAvailabilityProps {
|
|
nextStep: () => void;
|
|
defaultScheduleId?: number | null;
|
|
}
|
|
|
|
const SetupAvailability = (props: ISetupAvailabilityProps) => {
|
|
const { defaultScheduleId } = props;
|
|
|
|
const { t } = useLocale();
|
|
const { nextStep } = props;
|
|
|
|
const router = useRouter();
|
|
let queryAvailability;
|
|
if (defaultScheduleId) {
|
|
queryAvailability = trpc.useQuery(["viewer.availability.schedule", { scheduleId: defaultScheduleId }], {
|
|
enabled: router.isReady,
|
|
});
|
|
}
|
|
|
|
const availabilityForm = useForm({
|
|
defaultValues: {
|
|
schedule: queryAvailability?.data?.availability || DEFAULT_SCHEDULE,
|
|
},
|
|
});
|
|
|
|
const mutationOptions = {
|
|
onError: (error: TRPCClientErrorLike<AppRouter>) => {
|
|
throw new Error(error.message);
|
|
},
|
|
onSuccess: () => {
|
|
nextStep();
|
|
},
|
|
};
|
|
const createSchedule = trpc.useMutation("viewer.availability.schedule.create", mutationOptions);
|
|
const updateSchedule = trpc.useMutation("viewer.availability.schedule.update", mutationOptions);
|
|
return (
|
|
<Form
|
|
className="w-full bg-white text-black dark:bg-opacity-5 dark:text-white"
|
|
form={availabilityForm}
|
|
handleSubmit={async (values) => {
|
|
try {
|
|
if (defaultScheduleId) {
|
|
await updateSchedule.mutate({
|
|
scheduleId: defaultScheduleId,
|
|
name: t("default_schedule_name"),
|
|
...values,
|
|
});
|
|
} else {
|
|
await createSchedule.mutate({
|
|
name: t("default_schedule_name"),
|
|
...values,
|
|
});
|
|
}
|
|
} catch (error) {
|
|
if (error instanceof Error) {
|
|
// setError(error);
|
|
// @TODO: log error
|
|
}
|
|
}
|
|
}}>
|
|
<Schedule control={availabilityForm.control} name="schedule" weekStart={1} />
|
|
|
|
<div>
|
|
<Button
|
|
data-testid="save-availability"
|
|
type="submit"
|
|
className="mt-2 w-full justify-center p-2 text-sm sm:mt-8"
|
|
disabled={availabilityForm.formState.isSubmitting}>
|
|
{t("next_step_text")} <ArrowRightIcon className="ml-2 h-4 w-4 self-center" />
|
|
</Button>
|
|
</div>
|
|
</Form>
|
|
);
|
|
};
|
|
|
|
export { SetupAvailability };
|