-
Notifications
You must be signed in to change notification settings - Fork 7.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: error message for invalid variables in custom event name #7426
Merged
CarinaWolli
merged 15 commits into
main
from
7305-cal-1144-custom-event-type-name-differentiate-bw-valid-invalid-variable
Mar 6, 2023
Merged
Changes from 6 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
c39b0ec
feat: add custom validate name util
G3root 04f346c
refactor: separate custom event type modal into a
G3root 2b00d37
feat: add validation to zod
G3root 7dabf16
chore: add i18n key
G3root 5b9d3d9
feat: add dynamic imports
G3root d0611d6
fix: padding
G3root 83bf62c
Merge branch 'main' into 7305-cal-1144-custom-event-type-name-differe…
emrysal e858c0d
Merge branch 'main' into 7305-cal-1144-custom-event-type-name-differe…
emrysal da45c82
Omit cache-hit exit 1, assuming it'll fail regardless
emrysal fe6c512
Merge branch 'main' into 7305-cal-1144-custom-event-type-name-differe…
emrysal 6639add
Merge branch 'main' into 7305-cal-1144-custom-event-type-name-differe…
e15266b
Merge branch 'main' into 7305-cal-1144-custom-event-type-name-differe…
G3root 9c6afee
Merge branch 'main' into 7305-cal-1144-custom-event-type-name-differe…
G3root ad7d14a
fix: type error
G3root df7b335
Merge branch 'main' into 7305-cal-1144-custom-event-type-name-differe…
emrysal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
import type { FC } from "react"; | ||
import type { SubmitHandler } from "react-hook-form"; | ||
import { FormProvider } from "react-hook-form"; | ||
import { useForm, useFormContext } from "react-hook-form"; | ||
|
||
import type { EventNameObjectType } from "@calcom/core/event"; | ||
import { getEventName } from "@calcom/core/event"; | ||
import { validateCustomEventName } from "@calcom/core/event"; | ||
import { useLocale } from "@calcom/lib/hooks/useLocale"; | ||
import { Button, Dialog, DialogClose, DialogFooter, DialogContent, TextField } from "@calcom/ui"; | ||
|
||
interface FormValues { | ||
customEventName: string; | ||
} | ||
|
||
interface CustomEventTypeModalFormProps { | ||
placeHolder: string; | ||
close: () => void; | ||
setValue: (value: string) => void; | ||
event: EventNameObjectType; | ||
defaultValue: string; | ||
} | ||
|
||
const CustomEventTypeModalForm: FC<CustomEventTypeModalFormProps> = (props) => { | ||
const { t } = useLocale(); | ||
const { placeHolder, close, setValue, event } = props; | ||
const { register, handleSubmit, watch, getValues } = useFormContext<FormValues>(); | ||
const onSubmit: SubmitHandler<FormValues> = (data) => { | ||
setValue(data.customEventName); | ||
close(); | ||
}; | ||
|
||
// const customEventName = watch("customEventName"); | ||
const previewText = getEventName({ ...event, eventName: watch("customEventName") }); | ||
const placeHolder_ = watch("customEventName") === "" ? previewText : placeHolder; | ||
|
||
return ( | ||
<form | ||
id="custom-event-name" | ||
onSubmit={(e) => { | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
const isEmpty = getValues("customEventName") === ""; | ||
if (isEmpty) { | ||
setValue(""); | ||
} | ||
|
||
handleSubmit(onSubmit)(e); | ||
}}> | ||
<TextField | ||
label={t("event_name_in_calendar")} | ||
type="text" | ||
placeholder={placeHolder_} | ||
{...register("customEventName", { | ||
validate: (value) => validateCustomEventName(value, t("invalid_event_name_variables")), | ||
})} | ||
className="mb-0" | ||
/> | ||
<div className="pt-6 text-sm"> | ||
<div className="mb-6 rounded-md bg-gray-100 p-2"> | ||
<h1 className="mb-2 ml-1 font-medium text-gray-900">{t("available_variables")}</h1> | ||
<div className="mb-2.5 flex font-normal"> | ||
<p className="ml-1 mr-5 w-28 text-gray-400">{`{Event type title}`}</p> | ||
<p className="text-gray-900">{t("event_name_info")}</p> | ||
</div> | ||
<div className="mb-2.5 flex font-normal"> | ||
<p className="ml-1 mr-5 w-28 text-gray-400">{`{Organiser}`}</p> | ||
<p className="text-gray-900">{t("your_full_name")}</p> | ||
</div> | ||
<div className="mb-2.5 flex font-normal"> | ||
<p className="ml-1 mr-5 w-28 text-gray-400">{`{Scheduler}`}</p> | ||
<p className="text-gray-900">{t("scheduler_full_name")}</p> | ||
</div> | ||
<div className="mb-1 flex font-normal"> | ||
<p className="ml-1 mr-5 w-28 text-gray-400">{`{Location}`}</p> | ||
<p className="text-gray-900">{t("location_info")}</p> | ||
</div> | ||
</div> | ||
<h1 className="mb-2 text-[14px] font-medium leading-4">{t("preview")}</h1> | ||
<div | ||
className="flex h-[212px] w-full rounded-md border-y bg-cover bg-center" | ||
style={{ | ||
backgroundImage: "url(/calendar-preview.svg)", | ||
}}> | ||
<div className="m-auto flex items-center justify-center self-stretch"> | ||
<div className="mt-3 ml-11 box-border h-[110px] w-[120px] flex-col items-start gap-1 rounded-md border border-solid border-black bg-gray-100 text-[12px] leading-3"> | ||
<p className="overflow-hidden text-ellipsis p-1.5 font-medium text-gray-900">{previewText}</p> | ||
<p className="ml-1.5 text-[10px] font-normal text-gray-600">8 - 10 AM</p> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</form> | ||
); | ||
}; | ||
|
||
interface CustomEventTypeModalProps { | ||
placeHolder: string; | ||
defaultValue: string; | ||
close: () => void; | ||
setValue: (value: string) => void; | ||
event: EventNameObjectType; | ||
} | ||
|
||
const CustomEventTypeModal: FC<CustomEventTypeModalProps> = (props) => { | ||
const { t } = useLocale(); | ||
|
||
const { defaultValue, placeHolder, close, setValue, event } = props; | ||
|
||
const methods = useForm<FormValues>({ | ||
defaultValues: { | ||
customEventName: defaultValue, | ||
}, | ||
}); | ||
|
||
return ( | ||
<Dialog open={true} onOpenChange={close}> | ||
<DialogContent | ||
title={t("custom_event_name")} | ||
description={t("custom_event_name_description")} | ||
type="creation" | ||
enableOverflow> | ||
<FormProvider {...methods}> | ||
<CustomEventTypeModalForm | ||
event={event} | ||
close={close} | ||
setValue={setValue} | ||
placeHolder={placeHolder} | ||
defaultValue={defaultValue} | ||
/> | ||
</FormProvider> | ||
<DialogFooter> | ||
<DialogClose>{t("cancel")}</DialogClose> | ||
|
||
<Button form="custom-event-name" type="submit" color="primary"> | ||
{t("create")} | ||
</Button> | ||
</DialogFooter> | ||
</DialogContent> | ||
</Dialog> | ||
); | ||
}; | ||
|
||
export default CustomEventTypeModal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is It possible to avoid using arbitrary values here?
cc @sean-brydon