Skip to content
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

fixed add org user error #944

Merged
merged 1 commit into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 51 additions & 46 deletions frontend/app/src/people/widgetViews/OrganizationDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,15 @@ const OrganizationDetails = (props: {
const getPaymentsHistory = useCallback(async () => {
if (!viewReportDisabled) {
const paymentHistories = await main.getPaymentHistories(uuid, 1, 2000);
const payments = paymentHistories.map((history: PaymentHistory) => {
if (!history.payment_type) {
history.payment_type = 'payment';
}
return history;
});
setPaymentsHistory(payments);
if (Array.isArray(paymentHistories)) {
const payments = paymentHistories.map((history: PaymentHistory) => {
if (!history.payment_type) {
history.payment_type = 'payment';
}
return history;
});
setPaymentsHistory(payments);
}
}
}, [main, uuid, viewReportDisabled]);

Expand Down Expand Up @@ -437,7 +439,7 @@ const OrganizationDetails = (props: {
<BudgetSmallHead>YOUR BALANCE</BudgetSmallHead>
<ViewBudgetTextWrap>
<Budget>
{orgBudget.toLocaleString()} <Grey>SATS</Grey>
{orgBudget ? orgBudget.toLocaleString() : 0} <Grey>SATS</Grey>
</Budget>
<Budget className="budget-small">
{satToUsd(orgBudget)} <Grey>USD</Grey>
Expand Down Expand Up @@ -486,44 +488,47 @@ const OrganizationDetails = (props: {
</HeadButtonWrap>
</UsersHeadWrap>
<UsersList>
{users.map((user: Person, i: number) => (
<User key={i}>
<UserImage src={user.img || avatarIcon} />
<UserDetails>
<UserName>{user.unique_name}</UserName>
<UserPubkey>{user.owner_pubkey}</UserPubkey>
</UserDetails>
<UserAction>
<IconWrap>
<MaterialIcon
disabled={addRolesDisabled}
icon={'settings'}
style={{
fontSize: 24,
cursor: 'pointer',
color: '#ccc'
}}
onClick={() => handleSettingsClick(user)}
/>
</IconWrap>
<IconWrap>
<MaterialIcon
icon={'delete'}
disabled={deleteUserDisabled}
style={{
fontSize: 24,
cursor: 'pointer',
color: '#ccc'
}}
onClick={() => {
setUser(user);
handleDeleteClick(user);
}}
/>
</IconWrap>
</UserAction>
</User>
))}
{users.map((user: Person, i: number) => {
const isUser = user.owner_pubkey === ui.meInfo?.owner_pubkey;
return (
<User key={i}>
<UserImage src={user.img || avatarIcon} />
<UserDetails>
<UserName>{user.unique_name}</UserName>
<UserPubkey>{user.owner_pubkey}</UserPubkey>
</UserDetails>
<UserAction>
<IconWrap>
<MaterialIcon
disabled={isUser || addRolesDisabled}
icon={'settings'}
style={{
fontSize: 24,
cursor: 'pointer',
color: '#ccc'
}}
onClick={() => handleSettingsClick(user)}
/>
</IconWrap>
<IconWrap>
<MaterialIcon
icon={'delete'}
disabled={isUser || deleteUserDisabled}
style={{
fontSize: 24,
cursor: 'pointer',
color: '#ccc'
}}
onClick={() => {
setUser(user);
handleDeleteClick(user);
}}
/>
</IconWrap>
</UserAction>
</User>
);
})}
</UsersList>
</UserWrap>
<DetailsWrap>
Expand Down
12 changes: 5 additions & 7 deletions frontend/app/src/people/widgetViews/OrganizationView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,14 @@ const Organizations = (props: { person: Person }) => {
const [organization, setOrganization] = useState<Organization>();
const [disableFormButtons, setDisableFormButtons] = useState(false);
const [toasts, setToasts]: any = useState([]);
const [user, setUser] = useState<Person>();
const { main, ui } = useStores();
const isMobile = useIsMobile();
const config = widgetConfigs['organizations'];
const formRef = useRef(null);
const isMyProfile = ui?.meInfo?.pubkey === props?.person?.owner_pubkey;

const user_pubkey = ui.meInfo?.owner_pubkey;

const schema = [...config.schema];

const initValues = {
Expand Down Expand Up @@ -168,9 +169,6 @@ const Organizations = (props: { person: Person }) => {
if (ui.selectedPerson) {
const orgs = await main.getUserOrganizations(ui.selectedPerson);
main.setDropDownOrganizations(orgs);

const user = await main.getPersonById(ui.selectedPerson);
setUser(user);
}
setIsLoading(false);
}, [main, ui.selectedPerson]);
Expand Down Expand Up @@ -207,12 +205,12 @@ const Organizations = (props: { person: Person }) => {
<OrganizationWrap key={key}>
<OrganizationData>
<OrganizationImg src={org.img || avatarIcon} />
<OrganizationBudget org={org} user_pubkey={user?.owner_pubkey ?? ''} />
<OrganizationBudget org={org} user_pubkey={user_pubkey ?? ''} />
<OrganizationActionWrap>
{ui.meInfo?.owner_pubkey && (
{user_pubkey && (
<ManageButton
org={org}
user_pubkey={user?.owner_pubkey ?? ''}
user_pubkey={user_pubkey ?? ''}
action={() => {
setOrganization(org);
setDetailsOpen(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ const ManageButton = (props: { user_pubkey: string; org: any; action: () => void
userHasRole(main.bountyRoles, userRoles, 'VIEW REPORT');

const getUserRoles = useCallback(async () => {
const userRoles = await main.getUserRoles(org.uuid, user_pubkey);
setUserRoles(userRoles);
try {
const userRoles = await main.getUserRoles(org.uuid, user_pubkey);
setUserRoles(userRoles);
} catch (e) {
console.error('User roles error', e);
}
}, [org.uuid, main, user_pubkey]);

useEffect(() => {
Expand Down
2 changes: 1 addition & 1 deletion handlers/organizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func CreateOrganizationUser(w http.ResponseWriter, r *http.Request) {
}

// check if the user is the organization admin
if pubKeyFromAuth == org.OwnerPubKey {
if orgUser.OwnerPubKey == org.OwnerPubKey {
w.WriteHeader(http.StatusUnauthorized)
json.NewEncoder(w).Encode("Cannot add organization admin as a user")
return
Expand Down
Loading