Skip to content

Commit

Permalink
fix: add org edit platform
Browse files Browse the repository at this point in the history
Signed-off-by: laixingyou <[email protected]>
  • Loading branch information
coder-sett committed Mar 8, 2024
1 parent 44f96a9 commit 0f41676
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
5 changes: 4 additions & 1 deletion apps/web/src/common/components/OrgEdit/ManageOrgEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,21 @@ const ManageOrgEdit = ({
level,
contributor,
name,
provider,
setShowEdit,
}: {
label?: string;
level?: string;
contributor?: string;
name?: string;
provider?: string;
setShowEdit: (b: boolean) => void;
}) => {
const { t } = useTranslation();
const [orgName, setOrgName] = useState(name || '');
const [date, setDate] = useState<RangeValue>(null);
const [form] = Form.useForm();

const onCheck = async () => {
try {
const values = await form.validateFields();
Expand All @@ -39,7 +42,7 @@ const ManageOrgEdit = ({
label,
level,
contributor,
platform: 'github',
platform: provider,
organizations: [{ orgName, firstDate, lastDate }],
});
} catch (errorInfo) {
Expand Down
6 changes: 4 additions & 2 deletions apps/web/src/common/components/OrgEdit/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ const OrgEdit = ({
organizations = [],
type = 'add',
index,
provider,
setShowEdit,
onSuccess,
}: {
organizations?: ContributorOrgInput[];
type?: 'add' | 'edit';
index?: number;
provider: string;
setShowEdit: (b: boolean) => void;
onSuccess?: () => void;
}) => {
Expand All @@ -51,12 +53,12 @@ const OrgEdit = ({
if (type === 'edit') {
organizations[index] = { orgName, firstDate, lastDate };
mutation.mutate({
platform: 'github',
platform: provider,
organizations: [...organizations],
});
} else {
mutation.mutate({
platform: 'github',
platform: provider,
organizations: [{ orgName, firstDate, lastDate }, ...organizations],
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ const MetricTable: React.FC<{
level={level}
contributor={currentName}
name={currentOrgName}
provider={origin}
setShowEdit={() => {
setOpenConfirm(false);
}}
Expand Down
21 changes: 13 additions & 8 deletions apps/web/src/modules/settings/profile/Organizations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import {
useModifyUserOrgsMutation,
ContributorOrgInput,
} from '@oss-compass/graphql';
import { cookieGetAuthProvider } from '@common/utils/cookie';

const OrgItem = ({ provider, index, organizations, onSuccess }) => {
const OrgItem = ({ org, index, organizations, onSuccess, provider }) => {
const customFormat = (date) => {
if (date.startsWith('2099')) {
return t('common:up_to_now');
Expand Down Expand Up @@ -41,7 +42,7 @@ const OrgItem = ({ provider, index, organizations, onSuccess }) => {
const arr = [...organizations];
arr.splice(index, 1);
mutation.mutate({
platform: 'github',
platform: provider,
organizations: [...arr],
});
};
Expand All @@ -52,21 +53,21 @@ const OrgItem = ({ provider, index, organizations, onSuccess }) => {
setShowEdit={setShowEdit}
organizations={organizations as ContributorOrgInput[]}
onSuccess={onSuccess}
provider={provider}
type={'edit'}
index={index}
/>
) : (
<div className="flex items-center justify-between border-b border-[#E7E7E7] py-4">
<div className="flex">
<div className="mr-2 w-[120px] font-bold">
<span className="line-clamp-1" title={provider.orgName}>
{provider.orgName}
<span className="line-clamp-1" title={org.orgName}>
{org.orgName}
</span>
</div>
<div className="flex text-[#868690]">
<div className="mr-2">{customFormat(provider?.firstDate)}</div>
{'-'}{' '}
<div className="ml-2">{customFormat(provider?.lastDate)}</div>
<div className="mr-2">{customFormat(org?.firstDate)}</div>
{'-'} <div className="ml-2">{customFormat(org?.lastDate)}</div>
</div>
</div>
<div className="flex">
Expand All @@ -88,6 +89,8 @@ const OrgItem = ({ provider, index, organizations, onSuccess }) => {
const Organizations = () => {
const { t } = useTranslation();
const { currentUser } = useSnapshot(userInfoStore);
const provider = cookieGetAuthProvider();

const contributingOrgs = currentUser.contributingOrgs.map((item) => {
return {
orgName: item.orgName,
Expand All @@ -112,10 +115,11 @@ const Organizations = () => {
return (
<OrgItem
key={item.orgName + index}
provider={item}
org={item}
index={index}
organizations={contributingOrgs as ContributorOrgInput[]}
onSuccess={onSuccess}
provider={provider}
/>
);
})}
Expand All @@ -125,6 +129,7 @@ const Organizations = () => {
setShowEdit={setShowEdit}
organizations={contributingOrgs as ContributorOrgInput[]}
onSuccess={onSuccess}
provider={provider}
/>
)}
<div className="mt-4">
Expand Down

0 comments on commit 0f41676

Please sign in to comment.