2023-04-05 18:14:46 +00:00
|
|
|
import type { SyntheticEvent } from "react";
|
|
|
|
import { useMemo, useState } from "react";
|
2022-09-12 22:04:33 +00:00
|
|
|
|
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
2023-05-02 11:44:05 +00:00
|
|
|
import { MembershipRole } from "@calcom/prisma/enums";
|
2022-09-12 22:04:33 +00:00
|
|
|
import { trpc } from "@calcom/trpc/react";
|
2023-06-29 07:47:16 +00:00
|
|
|
import { Button, Dialog, DialogContent, DialogFooter, Select } from "@calcom/ui";
|
2022-09-12 22:04:33 +00:00
|
|
|
|
|
|
|
type MembershipRoleOption = {
|
|
|
|
label: string;
|
|
|
|
value: MembershipRole;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default function MemberChangeRoleModal(props: {
|
|
|
|
isOpen: boolean;
|
|
|
|
currentMember: MembershipRole;
|
|
|
|
memberId: number;
|
|
|
|
teamId: number;
|
|
|
|
initialRole: MembershipRole;
|
|
|
|
onExit: () => void;
|
|
|
|
}) {
|
|
|
|
const { t } = useLocale();
|
|
|
|
|
|
|
|
const options = useMemo(() => {
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
label: t("member"),
|
|
|
|
value: MembershipRole.MEMBER,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: t("admin"),
|
|
|
|
value: MembershipRole.ADMIN,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: t("owner"),
|
|
|
|
value: MembershipRole.OWNER,
|
|
|
|
},
|
|
|
|
].filter(({ value }) => value !== MembershipRole.OWNER || props.currentMember === MembershipRole.OWNER);
|
|
|
|
}, [t, props.currentMember]);
|
|
|
|
|
|
|
|
const [role, setRole] = useState<MembershipRoleOption>(
|
|
|
|
options.find((option) => option.value === props.initialRole) || {
|
|
|
|
label: t("member"),
|
|
|
|
value: MembershipRole.MEMBER,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
const [errorMessage, setErrorMessage] = useState("");
|
|
|
|
const utils = trpc.useContext();
|
|
|
|
|
2022-11-10 23:40:01 +00:00
|
|
|
const changeRoleMutation = trpc.viewer.teams.changeMemberRole.useMutation({
|
2022-09-12 22:04:33 +00:00
|
|
|
async onSuccess() {
|
2022-11-10 23:40:01 +00:00
|
|
|
await utils.viewer.teams.get.invalidate();
|
feat: Org settings - profile,appearance, child teams, create new child (#9231)
* Initial commit
* Adding feature flag
* Desktop first banner, mobile pending
* Removing dead code and img
* AppInstallButtonBase
* WIP
* Adds Email verification template+translations for organizations (#9202)
* feat: Orgs Schema Changing `scopedMembers` to `orgUsers` (#9209)
* Change scopedMembers to orgMembers
* Change to orgUsers
* First step done
* Merge branch 'feat/organizations-onboarding' of github.com:calcom/cal.com into feat/organizations-onboarding
* Session logic to show org label
* Step 2 done, avatar not working
* List orgs and list teams specific if orgs exist
* Conditionally show org - fix settings layout - add labels for all pages
* Profile Page + update
* Org specific team creation
* appearance page
* Ensure members cant of org cant update settings in UI
* Fix update handler imports
* hide billing on sub teams
* Update profile slug page
* Letting duplicate slugs for teams to support orgs
* Add slug coliisions for org
* Covering null on unique clauses
* Covering null on unique clauses
* Extract to utils
* Update settings to use subdomain path in team url , team + org
* Supporting having the orgId in the session cookie
* Onboarding admins step
* Last step to create teams
* Update handler comments
* Upgrade ORG banner - disabled team banner for child teams
* Handle publishing ORGS
* Fix licenese issue
* Update packages/trpc/server/routers/viewer/teams/create.handler.ts
* Moving change password handler, improving verifying code flow
* Clearing error before submitting
* Reverting email testing api changes
* Reverting having the banner for now
* Consistent exported components
* Remove unneeded files from banner
* Removing uneeded code
* Fixing avatar selector
* Using meta component for head/descr
* Missing i18n strings
* A11ly
* Feedback
* Making an org avatar (temp)
* Add slug colission detection for user and team name
* Fix Import
* Remove update password func
* Fix module import over relative
* feat: organization event type filter (#9253)
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* Missing changes to support orgs schema changes
* Remove app install button sa its in 9337
* Remove i18n key not being used
* feat: Onboarding process to create an organization (#9184)
* Desktop first banner, mobile pending
* Removing dead code and img
* WIP
* Adds Email verification template+translations for organizations (#9202)
* First step done
* Merge branch 'feat/organizations-onboarding' of github.com:calcom/cal.com into feat/organizations-onboarding
* Step 2 done, avatar not working
* Covering null on unique clauses
* Onboarding admins step
* Last step to create teams
* Moving change password handler, improving verifying code flow
* Clearing error before submitting
* Reverting email testing api changes
* Reverting having the banner for now
* Consistent exported components
* Remove unneeded files from banner
* Removing uneeded code
* Fixing avatar selector
* Using meta component for head/descr
* Missing i18n strings
* Feedback
* Making an org avatar (temp)
* Check for subteams slug clashes with usernames
* Fixing create teams onsuccess
* feedback
* Making sure we check requestedSlug now
---------
Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com>
* feat: [CAL-1816] Organization subdomain support (#9345)
* Desktop first banner, mobile pending
* Removing dead code and img
* WIP
* Adds Email verification template+translations for organizations (#9202)
* First step done
* Merge branch 'feat/organizations-onboarding' of github.com:calcom/cal.com into feat/organizations-onboarding
* Step 2 done, avatar not working
* Covering null on unique clauses
* Onboarding admins step
* Last step to create teams
* Moving change password handler, improving verifying code flow
* Clearing error before submitting
* Reverting email testing api changes
* Reverting having the banner for now
* Consistent exported components
* Remove unneeded files from banner
* Removing uneeded code
* Fixing avatar selector
* Using meta component for head/descr
* Missing i18n strings
* Feedback
* Making an org avatar (temp)
* Check for subteams slug clashes with usernames
* Fixing create teams onsuccess
* Covering users and subteams, excluding non-org users
* Unpublished teams shows correctly
* Create subdomain in Vercel
* feedback
* Renaming Vercel env vars
* Vercel domain check before creation
* Supporting cal-staging.com
* Change to have vercel detect it
* vercel domain check data message error
* Remove check domain
* Making sure we check requestedSlug now
* Feedback and unneeded code
* Reverting unneeded changes
* Unneeded changes
---------
Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com>
* Vercel subdomain creation in PROD only
* feat: organization settings general and members page (#9266)
* feat: organization settings general page
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* feat: add members page
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* chore: remove
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* fix: use invalidate
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* fix: delete mutation
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* fix: remove organization id
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* chore
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* fix: use zod schema
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
---------
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* Type fixes
* Reverting changes
* Update UsernameTextfield.tsx
* More reverts
* Update next-auth-options.ts
* Update common.json
* Type fixes
* Include invite token for orgs
* Update org schema
* Make token settings optional as it isnt used in orgs yet
* Fix missing prop
---------
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
Co-authored-by: Leo Giovanetti <hello@leog.me>
Co-authored-by: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com>
Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com>
Co-authored-by: zomars <zomars@me.com>
Co-authored-by: Hariom Balhara <hariombalhara@gmail.com>
2023-06-15 17:27:39 +00:00
|
|
|
await utils.viewer.organizations.listMembers.invalidate();
|
|
|
|
|
2022-09-12 22:04:33 +00:00
|
|
|
props.onExit();
|
|
|
|
},
|
|
|
|
async onError(err) {
|
|
|
|
setErrorMessage(err.message);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
function changeRole(e: SyntheticEvent) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
changeRoleMutation.mutate({
|
|
|
|
teamId: props.teamId,
|
|
|
|
memberId: props.memberId,
|
|
|
|
role: role.value,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<Dialog open={props.isOpen} onOpenChange={props.onExit}>
|
2023-01-24 14:00:45 +00:00
|
|
|
<DialogContent type="creation">
|
2022-09-12 22:04:33 +00:00
|
|
|
<>
|
|
|
|
<div className="mb-4 sm:flex sm:items-start">
|
|
|
|
<div className="text-center sm:text-left">
|
2023-06-29 07:47:16 +00:00
|
|
|
<h3
|
|
|
|
className="text-emphasis !font-cal text-semibold leading-20 text-xl font-medium"
|
|
|
|
id="modal-title">
|
2022-09-12 22:04:33 +00:00
|
|
|
{t("change_member_role")}
|
|
|
|
</h3>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<form onSubmit={changeRole}>
|
|
|
|
<div className="mb-4">
|
2023-04-05 18:14:46 +00:00
|
|
|
<label className="text-default mb-2 block text-sm font-medium tracking-wide" htmlFor="role">
|
2022-09-12 22:04:33 +00:00
|
|
|
{t("role")}
|
|
|
|
</label>
|
|
|
|
{/*<option value="OWNER">{t("owner")}</option> - needs dialog to confirm change of ownership */}
|
|
|
|
<Select
|
|
|
|
isSearchable={false}
|
|
|
|
options={options}
|
|
|
|
value={role}
|
|
|
|
onChange={(option) => option && setRole(option)}
|
|
|
|
id="role"
|
2023-04-05 18:14:46 +00:00
|
|
|
className="border-default mt-1 block w-full rounded-md text-sm"
|
2022-09-12 22:04:33 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
{errorMessage && (
|
|
|
|
<p className="text-sm text-red-700">
|
|
|
|
<span className="font-bold">Error: </span>
|
|
|
|
{errorMessage}
|
|
|
|
</p>
|
|
|
|
)}
|
2023-07-21 08:46:16 +00:00
|
|
|
<DialogFooter className="mt-12">
|
2022-09-12 22:04:33 +00:00
|
|
|
<Button type="button" color="secondary" onClick={props.onExit}>
|
|
|
|
{t("cancel")}
|
|
|
|
</Button>
|
2023-06-29 07:47:16 +00:00
|
|
|
<Button type="submit" color="primary" className="me-2 ms-2">
|
|
|
|
{t("save")}
|
|
|
|
</Button>
|
|
|
|
</DialogFooter>
|
2022-09-12 22:04:33 +00:00
|
|
|
</form>
|
|
|
|
</>
|
|
|
|
</DialogContent>
|
|
|
|
</Dialog>
|
|
|
|
);
|
|
|
|
}
|