-
Notifications
You must be signed in to change notification settings - Fork 3
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
Allow re-enrollment in recipe #51
base: main
Are you sure you want to change the base?
Conversation
This change checks for existing enrollments, and if present shows the user a modal asking whether they want to force enroll. If so, it unenrolls them from the previous one, and deletes it before proceeding with the new enrollment. Fixes #50
const { addToast } = useToastsContext(); | ||
|
||
const recipe = useMemo<NimbusExperiment | null>(() => { |
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.
We don't actually know its a valid NimbusExperiment here, unfortunately. It should be unknown | null
setEnrollError(null); | ||
}, [setEnrollError]); | ||
|
||
function EnrollmentError( |
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.
This should be a top level function, not nested inside the component fn
if its nested inside, it will always trigger a re-render because the function is redefined every time the component is called
<Modal.Header closeButton> | ||
<Modal.Title>Force Enrollment</Modal.Title> | ||
</Modal.Header> | ||
<Modal.Body>{EnrollmentError(slug, enrollError)}</Modal.Body> |
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.
EnrollmentError is a component:
<Modal.Body>{EnrollmentError(slug, enrollError)}</Modal.Body> | |
<Modal.Body><EnrollmentError slug{slug} enrollError={enrollError} /></Modal.Body> |
if (activeEnrollment) { | ||
return ( | ||
<p> | ||
There is an active enrollment for the slug: <strong>{slug}</strong>. |
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.
This actually might not be the same slug.
There is an active enrollment for the slug: <strong>{slug}</strong>. | |
There is an active enrollment for the slug: <strong>{activeEnrollment}</strong>. |
if (activeEnrollment && slugExistsInStore) { | ||
return ( | ||
<p> | ||
There is already an enrollment for the slug: <strong>{slug}</strong>. |
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.
This is only true if slug == activeEnrollment
There are technically two cases, slug == activeEnrollment and slug !== activeEnrollment (ie there is already an active enrollment for this feature but the slug doesnt match this one)
const recipe = useMemo<NimbusExperiment | null>(() => { | ||
try { | ||
return JSON.parse(jsonInput) as NimbusExperiment; | ||
} catch { | ||
return null; | ||
} | ||
}, [jsonInput]); | ||
|
||
const slug = recipe?.slug || ""; |
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.
We're doing this all to get the slug. Instead, lets change this slightly:
type EnrollError = EnrollInExperimentResult["error"] & { slug: string; };
const [enrollError, setEnrollError] = useState<EnrollError | null>(null);
// line 63
setEnrollError({ slug: parsedRecipe.slug ?? "", ...result.error });
Since we're already parsing this to pass it off to the API, we may as well grab the slug there and only if we're parsing successfully and there is an error. otherwise, just wasted work and threading data through awkwardly.
return ( | ||
<p> | ||
There is an active enrollment for the slug: <strong>{slug}</strong>. | ||
Would you like to unenroll from the active enrollment and re-enroll |
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.
Would you like to unenroll from the active enrollment and re-enroll | |
Would you like to unenroll from the active enrollment and enroll |
<p> | ||
There is already an enrollment for the slug: <strong>{slug}</strong>. | ||
Would you like to proceed with force enrollment by unenrolling, | ||
deleting, and re-enrolling into the new configuration? |
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.
deleting, and re-enrolling into the new configuration? | |
deleting, and enrolling into the new configuration? |
<p> | ||
There is an inactive enrollment stored for the slug:{" "} | ||
<strong>{slug}</strong>. Would you like to delete the inactive | ||
enrollment and re-enroll into the new configuration? |
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.
enrollment and re-enroll into the new configuration? | |
enrollment and enroll into the new configuration? |
This change checks for existing enrollments, and if present shows the user a modal asking whether they want to force enroll. If so, it unenrolls them from the previous one, and deletes it before proceeding with the new enrollment.
Fixes #50